home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap06 / howto01 / drwsutl4.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-03-07  |  127.5 KB  |  3,475 lines

  1. unit Drwsutl4;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, ShellAPI, FileCtrl, DRWSUtl1;
  8.  
  9. const
  10.   EOC_CHANGEDIR = 1;  { Error Operation Code for change directory failure }
  11.   EOC_SOURCECOPY = 2; { Error Operation Code for source copy failure      }
  12.   EOC_DESTCOPY = 3;   { Error Operation Code for destination copy failure }
  13.   EOC_DELETEFILE = 4; { Error Operation Code for file delete failure      }
  14.   EOC_DELETEDIR = 5;  { Error Operation Code for directory delete failure }
  15.   EOC_RENAMEFILE = 6; { Error Operation Code for renaming failure         }
  16.   EOC_MAKEDIR = 7;    { Error Operation Code for MkDir failure            }
  17.   EOC_SETATTR = 8;    { Error Operation Code for Set Attributes failure   }
  18.  
  19.   FAC_COPY = 1;       { File Action Code for recursive copying            }
  20.   FAC_MOVE = 2;       { File Action Code for recursive moving             }
  21.   FAC_DELETE = 3;     { File Action Code for recursive deletion           }
  22.  
  23.   KBMJ_SINGLE = 1;   { Keyboard mouse motion constant for single pixel moves }
  24.   KBMJ_SMALL = 10;    { Keyboard mouse motion constant for single pixel moves }
  25.   KBMJ_LARGE = 50;    { Keyboard mouse motion constant for single pixel moves }
  26.  
  27.   CR_KEYSET = 6; { ID for special keypress cursor }
  28.   CR_NULL = 7;   { ID for Null (blank) cursor     }
  29. type
  30.   { This is a descendant of TFileListbox }
  31.   { Which puts icons of files into the   }
  32.   { Objects array rather than the stand- }
  33.   { ard bitmaps.                         }
  34.   TIconFileListBox = class( TFileListBox )
  35.   public
  36.     { public methods and data }
  37.     procedure ReadFileNames; override;
  38.     function GetNextSelection( SourceDirectory : String;
  39.               var CurrentItem : Integer ) : String;
  40.     constructor Create(AOwner : TComponent); override; { override create    }
  41.     procedure TheDblClick( Sender : TObject );{ This holds override dblclick }
  42.   end;
  43.   TFileWorkBench = class( TComponent )
  44.   public
  45.     GlobalError        : Integer;  { This is used by FMXUCopyFile for er code }
  46.     GlobalErrorType    : Integer;  { This holds the Operation code            }
  47.     function ForceTrailingBackSlash( const TheFileName : String ) : String;
  48.     function StripNonRootTrailingBackSlash(
  49.               const TheFileName : String ) : String;
  50.     procedure GetFileAttributes( TheFile : String; var IsDirectory , IsArchive ,
  51.                 IsVolumeID , IsHidden , IsReadOnly , IsSysFile : Boolean );
  52.     procedure HandleIOException( TheOpCode : Integer; ThePath : String;
  53.                                  TheMessage : String; TheCode : Integer );
  54.     procedure HandleDOSError( TheOpCode : Integer; ThePath : String;
  55.                 TheCode : Integer );
  56.     function CopyFile( TargetPath ,
  57.                DestinationPath : String ) : Boolean;
  58.     procedure ChangeTheDirectory( NewPath : String );
  59.     procedure ChangeTheDriveAndDirectory( NewDrive : Integer );
  60.     procedure CopyTheFile( OldPath , NewPath : String );
  61.     procedure MoveTheFile( OldPath , NewPath : String );
  62.     procedure DeleteTheFile( ThePath : String );
  63.     procedure RenameTheFile( OldPath , NewName : String );
  64.     procedure CreateNewDirectory( NewPath : String );
  65.     procedure RemoveDirectory( ThePath : String );
  66.     procedure SetFileAttributes( TheFile  : String; TheAttributes : Integer );
  67.     procedure RecursivelyCopyDirectory( OldPath , NewPath : String );
  68.     procedure RecursivelyMoveDirectory( OldPath , NewPath : String );
  69.     procedure RecursivelyDeleteDirectory( ThePath : String );
  70.     procedure HandleRecursiveAction( StartingPath , NewPath : String;
  71.                ActionCode : Integer );
  72.   end;
  73.   TFileIconPanel = class( TPanel )
  74.   private
  75.     { Private declarations }
  76.     FHighlightColor : TColor;                 { This holds bright edge bevel }
  77.     FShadowColor    : TColor;                 { This holds dark edge bevel   }
  78.     procedure TheMouseDown(Sender: TObject;
  79.       Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  80.     procedure TheMouseMove( Sender: TObject; Shift: TShiftState;
  81.       X, Y: Integer);
  82.     procedure TheMouseUp(Sender: TObject;
  83.       Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  84.     procedure WMLButtonDblClk(var Message: TWMLButtonDblClk);
  85.      message WM_LBUTTONDBLCLK;
  86.     procedure TheDragOver(Sender, Source: TObject; X,
  87.       Y: Integer; State: TDragState; var Accept: Boolean);
  88.     procedure TheDragDrop(Sender, Source: TObject; X,
  89.       Y: Integer);
  90.   protected                                   { event method procedure.      }
  91.     { Protected declarations }
  92.     procedure Paint; override;                { This allows custom painting  }
  93.   public
  94.     { Public declarations }
  95.     FTheIcon : TIcon;                         { This is the display icon    }
  96.     FTheBMP  : TBitmap;                       { This holds a thumbnail image}
  97.     FTheName : String;                        { This is the filename        }
  98.     FTheLabel : TLabel;                       { This is the display label   }
  99.     Selected : Boolean;                       { This holds selection status }
  100.     constructor Create(AOwner : TComponent); override; { override create    }
  101.     procedure Initialize( PanelX              ,             { Left          }
  102.                           PanelY              ,             { Top           }
  103.                           PanelWidth          ,             { Width         }
  104.                           PanelHeight         ,             { Height        }
  105.                           PanelBevelWidth     ,             { Bevel Width   }
  106.                           LabelFontSize         : Integer;  { Font size     }
  107.                           PanelColor          ,             { Main color    }
  108.                           PanelHighlightColor ,             { Bright color  }
  109.                           PanelShadowColor    ,             { Dark color    }
  110.                           LabelTextColor        : TColor;   { Text color    }
  111.                           TheFilename         ,             { Filename      }
  112.                           LabelFontName         : String;   { Font name     }
  113.                           LabelFontStyle        : TFontStyles;  { Font style}
  114.                           ExtraData             : Integer       );  { Drive }
  115.     destructor Destroy; override;             { override destroy to free    }
  116.   end;
  117.   TFileIconPanelScrollBox = class( TScrollBox )
  118.   public
  119.     { Public methods and data }
  120.     TheFWB              : TFileWorkBench; { Used for file manipulation         }
  121.     IconsNeedRefreshing : Boolean;                   { Flag to redo display    }
  122.     TheIconSize        : Integer;   { Holds Individual Icon size               }
  123.     TheIconSpacing     : Integer;   { Holds total icon footprint               }
  124.     MaxIconsInARow     : Integer;   { Set for screen size.                     }
  125.     TheStoredHandle    : HWnd;
  126.     TheParentForm      : TForm;
  127.     procedure Update;                                { Called to reset display }
  128.     constructor Create( AOwner : TComponent ); override;  { Override inherited }
  129.     procedure ClearTheFIPs;                          { Clears the FIPs safely  }
  130.     procedure AddDriveIcons( var XCounter , YCounter : Integer ); { Add drives }
  131.     procedure GetColorsForFileIcon( TheFile : String;
  132.                var BC , HC , SC , TC : TColor );
  133.     procedure GetIconsForEntireDirectory( TargetPath  : String );
  134.     function GetNextSelection( SourceDirectory : String;
  135.               var CurrentItem : Integer ) : String;
  136.     procedure DisplayRecursiveSearchResults(
  137.       TheStartingDirectory : String );
  138.   end;
  139.   TIOManager = class( TComponent )
  140.   public
  141.     Parent : TForm;
  142.     WhichButton : TMouseButton;
  143.     WhichState  : TShiftState;
  144.     CLState ,
  145.     NLState ,
  146.     SLState   : Boolean;
  147.     function IsCapsLockDown : Boolean;
  148.     function ISNumLockDown : Boolean;
  149.     function IsScrollLockDown : Boolean;
  150.     procedure InitLocks;
  151.     procedure ReadLocks( var TheCL , TheNL , TheSL : Boolean );
  152.     procedure SetLocks( TheCL , TheNL , TheSL : Boolean );
  153.     function WasLeftPressed : Boolean;
  154.     function WasRightPressed : Boolean;
  155.     function WasMiddlePressed : Boolean;
  156.     function WasALTPressed : Boolean;
  157.     function WasSHIFTPressed : Boolean;
  158.     function WasCTRLPressed : Boolean;
  159.     procedure OnF1Pressed(Sender: TObject; var Key: Word;
  160.      Shift: TShiftState);
  161.     procedure OnF2Pressed(Sender: TObject; var Key: Word;
  162.      Shift: TShiftState);
  163.     procedure OnF3Pressed(Sender: TObject; var Key: Word;
  164.      Shift: TShiftState);
  165.     procedure OnF4Pressed(Sender: TObject; var Key: Word;
  166.      Shift: TShiftState);
  167.     procedure OnF5Pressed(Sender: TObject; var Key: Word;
  168.      Shift: TShiftState);
  169.     procedure OnF6Pressed(Sender: TObject; var Key: Word;
  170.      Shift: TShiftState);
  171.     procedure OnF7Pressed(Sender: TObject; var Key: Word;
  172.      Shift: TShiftState);
  173.     procedure OnF8Pressed(Sender: TObject; var Key: Word;
  174.      Shift: TShiftState);
  175.     procedure OnF9Pressed(Sender: TObject; var Key: Word;
  176.      Shift: TShiftState);
  177.     procedure OnF10Pressed(Sender: TObject; var Key: Word;
  178.      Shift: TShiftState);
  179.     procedure OnF11Pressed(Sender: TObject; var Key: Word;
  180.      Shift: TShiftState);
  181.     procedure OnF12Pressed(Sender: TObject; var Key: Word;
  182.      Shift: TShiftState);
  183.  end;
  184.  TMouseManager = class( TComponent )
  185.  public
  186.    TheMX : Integer;
  187.    TheMY : Integer;
  188.    Old_X ,
  189.    Old_Y ,
  190.    New_X ,
  191.    New_Y   : Integer;
  192.    StoredCursor : Integer;
  193.    BitmapCursor  : Boolean;
  194.    IconCursor    : Boolean;
  195.    CursorBMP     : TBitmap;
  196.    CursorIcon    : TIcon;
  197.    IsAnimated    : Boolean;
  198.    TheTimer      : TTimer;
  199.    TheAnimationList : TList;
  200.    CurrentAnimationPointer : Integer;
  201.    AnimationInterval : Integer;
  202.    SavedDC ,
  203.    GlobalDC : HDC;
  204.    GlobalCanvas : TCanvas;
  205.    WorkSpaceBMP : TBitmap;
  206.    BackGroundBMP : TBitmap;
  207.    constructor Create( AOwner : TComponent ); override;
  208.    destructor Destroy; override;
  209.    procedure InitializeNormal;
  210.    procedure InitializeBitmap( TheBmp : TBitmap );
  211.    procedure InitializeIcon( TheIcon : TIcon );
  212.    procedure InitializeAnimated( TheIcon : TIcon; TheInterval : Integer;
  213.                                  TheIconList : TList );
  214.    procedure GetMousePosition( var MouseX , MouseY : Integer );
  215.    procedure SetMousePosition( MouseX , MouseY : Integer );
  216.    procedure MoveSinglePixelLeft;
  217.    procedure MoveSinglePixelRight;
  218.    procedure MoveSinglePixelUp;
  219.    procedure MoveSinglePixelDown;
  220.    procedure MoveSmallJumpLeft;
  221.    procedure MoveSmallJumpRight;
  222.    procedure MoveSmallJumpUp;
  223.    procedure MoveSmallJumpDown;
  224.    procedure MoveLargeJumpLeft;
  225.    procedure MoveLargeJumpRight;
  226.    procedure MoveLargeJumpUp;
  227.    procedure MoveLargeJumpDown;
  228.    procedure StartBitmapCursor( TheX , TheY : Integer );
  229.    procedure MoveBitmapCursor( TheX , TheY : Integer );
  230.    procedure EndBitmapCursor( TheX , TheY : Integer );
  231.    procedure StartIconCursor( TheX , TheY : Integer );
  232.    procedure MoveIconCursor( TheX , TheY : Integer );
  233.    procedure EndIconCursor( TheX , TheY : Integer );
  234.    procedure StartAnimatedIconCursor( TheX , TheY : Integer );
  235.    procedure EndAnimatedIconCursor( TheX , TheY : Integer );
  236.    procedure MoveAnimatedIconCursor( TheX , TheY : Integer );
  237.    procedure TimerAction( Sender : TObject );
  238.  end;
  239.  
  240.   { This procedure gets an icon for a file using FindExecutable  }
  241.   { and ExtractIcon. (assumes file/dir is passed)                }
  242.   procedure GetIconForFile( TheName : String; var TheIcon : TIcon );
  243.   { This procedure spaces out the bitbtn components on a tpanel }
  244.   procedure SpacePanelButtons( WhichPanel : TPanel );
  245.     procedure FMXUCopyFile(const FileName, DestName: String; var GlobalErrorType ,
  246.                GlobalErrorCode : Integer );
  247.  
  248. var TheIOManager : TIOManager;
  249.     TheMouseManager : TMouseManager;
  250.     GlobalAbortFlag : Boolean;
  251.     SavedForm : TForm;
  252.     SavedControl : TFileIconPanel;
  253.     OtherSavedControl : TFileIconPanelScrollbox;
  254.     Savedhandle : HWnd;
  255.     IconDragging : boolean;
  256.     GlobalSource : TObject;
  257.     TheTempBitmap : TBitmap;
  258.     BitmapDragging : boolean;
  259.     ThumbNailWidth,
  260.     ThumbNailHeight : Integer;
  261.  
  262. implementation
  263. {$R DRWSUTL4.RES}                 { Import custom resource file }
  264. uses UFMGR30,DRWSUtl6;
  265.  
  266. { It has been edited to return viable error codes!             }
  267. procedure FMXUCopyFile(const FileName, DestName: String; var GlobalErrorType ,
  268.             GlobalErrorCode : Integer );
  269. var
  270.   CopyBuffer: Pointer; { buffer for copying }
  271.   BytesCopied: Longint;
  272.   TheAttr : Integer;
  273.   Source, Dest: Integer; { handles }
  274. const
  275.   ChunkSize: Longint = 8192; { copy in 8K chunks }
  276. begin
  277.   GetMem(CopyBuffer, ChunkSize); { allocate the buffer }
  278.   Source := FileOpen(FileName, fmShareDenyWrite); { open source file }
  279.   if Source < 0 then
  280.   begin  { error creating source file }
  281.     GlobalErrorType := EOC_SOURCECOPY;
  282.     GlobalErrorCode := -IOResult;
  283.     if GlobalErrorCode = 0 then GlobalErrorCode := -157;
  284.     FreeMem( CopyBuffer, ChunkSize );
  285.     exit;
  286.   end;
  287.   Dest := FileCreate(DestName); { create output file; overwrite existing }
  288.   if Dest < 0 then
  289.   begin  { error creating destination file }
  290.     FileClose( Source );
  291.     GlobalErrorType := EOC_DESTCOPY;
  292.     GlobalErrorCode := -IOResult;
  293.     if GlobalErrorCode = 0 then GlobalErrorCode := -159;
  294.     FreeMem( CopyBuffer , ChunkSize );
  295.     exit;
  296.   end;
  297.   {$I-}
  298.   repeat
  299.     BytesCopied := FileRead(Source, CopyBuffer^, ChunkSize); { read chunk}
  300.     if BytesCopied > 0 then { if we read anything... }
  301.     FileWrite(Dest, CopyBuffer^, BytesCopied); { ...write chunk }
  302.   until BytesCopied < ChunkSize; { until we run out of chunks }
  303.   {$I+}
  304.   GlobalErrorCode := -IOResult;  { get any error code which happens during copying }
  305.   FileClose(Dest); { close the destination file }
  306.   FileClose(Source); { close the source file }
  307.   FreeMem(CopyBuffer, ChunkSize); { free the buffer }
  308. end;
  309.  
  310. { This procedure spaces out the bitbtn components on a tpanel }
  311. procedure SpacePanelButtons( WhichPanel : TPanel );
  312. var TheCalculatedSpacing     ,            { Holds primary spacing }
  313.     TheFullCalculatedSpacing   : Integer; { Holds full spacing    }
  314.     Counter_1                  : Integer; { Loop counter          }
  315.     TotalIBs                   : Integer; { Gets total buttons    }
  316. begin
  317.   { Set up spacing values }
  318.   TotalIBs := WhichPanel.ControlCount;
  319.   TheCalculatedSpacing := (( WhichPanel.Width - 6 - ( TotalIbs * 49 ))
  320.    div ( TotalIbs + 1 ));
  321.   TheFullCalculatedSpacing := TheCalculatedSpacing + 49;
  322.   { Loop through all imported buttons and set their Left values }
  323.   for Counter_1 := 1 to WhichPanel.ControlCount do
  324.   begin
  325.     if Counter_1 = 1 then
  326.     begin
  327.       TBitBtn( WhichPanel.Controls[ Counter_1 - 1 ] ).Left := 3 +
  328.        TheCalculatedSpacing;
  329.     end
  330.     else
  331.     begin
  332.       TBitBtn( WhichPanel.Controls[ Counter_1 - 1 ] ).Left := 3 +
  333.        (( Counter_1 - 1 ) * TheFullCalculatedSpacing ) + TheCalculatedSpacing;
  334.     end;
  335.   end;
  336. end;
  337.  
  338. { This procedure gets an icon for a file using FindExecutable  }
  339. { and ExtractIcon. (assumes file/dir is passed)                }
  340. procedure GetIconForFile( TheName : String; var TheIcon : TIcon );
  341. var TheExt           : String; { File extension holder }
  342.     TheOtherPChar  ,           { Windows ASCIIZ string }
  343.     ThePChar         : PChar;  { Windows ASCIIZ string }
  344.     Dummy : Word;
  345. begin
  346.   { Check for directory and if so get directory icon from RES file }
  347.   if (( FileGetAttr( TheName ) and faDirectory ) = faDirectory ) then
  348.   begin
  349.     { Set up the PChar to communicate with Windows }
  350.     GetMem( TheOtherPChar , 255 );
  351.     { Convert Pascal-style string to ASCIIZ Pchar }
  352.     StrPCopy( TheOtherPChar , 'DIRECTORY' );
  353.     { Use API call to return icon handle of Icon Resource in FILECTRL.RES }
  354.     TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  355.     { Release memory from PChar }
  356.     FreeMem( TheOtherPChar , 255 );
  357.     { Leave }
  358.     exit;
  359.   end;
  360.   { Assume archive file; get its extension }
  361.   TheExt := Uppercase( ExtractFileExt( TheName ));
  362.   { If not an executable/image file then use FindExecutable to get icon }
  363.   if (( TheExt <> '.EXE' ) and ( TheExt <> '.BAT' ) and
  364.       ( TheExt <> '.PIF' ) and ( TheExt <> '.COM' )) then
  365.   begin
  366.     { Grab three chunks of memory }
  367.     GetMem( ThePChar , 255 );
  368.     { Set up the name and its directory in Windows string formats }
  369.     StrPCopy( ThePChar, TheName );
  370.     Dummy := 65535;
  371.     {**** Windows 95 Specialized call ****** }
  372.     TheIcon.Handle := ExtractAssociatedIcon( hInstance , ThePChar , Dummy );
  373.     if TheIcon.Handle = 0 then
  374.     begin
  375.       GetMem( TheOtherPChar , 255 );
  376.       StrPCopy( TheOtherPChar , 'NOICON' );
  377.       TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  378.       FreeMem( TheOtherPChar , 255 );
  379.       exit;
  380.     end;
  381.     FreeMem( ThePChar , 255 );
  382.   end
  383.   else
  384.   { Assume Windows Executable file, so get icon from it with ExtractIcon API }
  385.   begin
  386.     GetMem( ThePChar , 255 );
  387.     StrPCopy( ThePChar , TheName );
  388.     { Try to get first icon for file }
  389.     Dummy := 65535;
  390.     TheIcon.Handle := ExtractAssociatedIcon( hInstance , ThePChar , Dummy );
  391.     FreeMem( ThePChar , 255 );
  392.     { If handle is 0 invalid icon format so use default from RES file }
  393.     if TheIcon.Handle = 0 then
  394.     begin
  395.       GetMem( TheOtherPChar , 255 );
  396.       StrPCopy( TheOtherPChar , 'NOICON' );
  397.       TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  398.       FreeMem( TheOtherPChar , 255 );
  399.       exit;
  400.     end;
  401.   end;
  402. end;
  403.  
  404. { This creates the TMouseManager and inits vars to null }
  405. constructor TMouseManager.Create( AOwner : TComponent );
  406. begin
  407.   { Call inherited FIRST! }
  408.   inherited Create( AOwner );
  409.   { Set all variables to 0 , false or nil }
  410.   TheMX := 0;
  411.   TheMY := 0;
  412.   Old_X  := 0;
  413.   Old_Y  := 0;
  414.   New_X  := 0;
  415.   New_Y  := 0;
  416.   StoredCursor := 0;
  417.   BitmapCursor  := false;
  418.   IconCursor    := false;
  419.   CursorBMP     := nil;
  420.   CursorIcon    := nil;
  421.   IsAnimated    := false;
  422.   TheTimer      := nil;
  423.   TheAnimationList := nil;
  424.   CurrentAnimationPointer := 0;
  425.   AnimationInterval := 0;
  426.   SavedDC := 0;
  427.   GlobalDC := 0;
  428.   GlobalCanvas := nil;
  429.   WorkSpaceBMP := nil;
  430.   BackGroundBMP := nil;
  431. end;
  432.  
  433. { This destroys the tmousemanager and releases all resources }
  434. destructor TMouseManager.Destroy;
  435. begin
  436.   { Free any assigned resources (the moving bmp ones already are gone) }
  437.   if assigned( TheTimer ) then
  438.    TheTimer.Free;
  439.   if assigned( TheAnimationList ) then
  440.    TheAnimationList.Free;
  441.   Inherited Destroy;
  442. end;
  443.  
  444. { This sets up the mouse manager for normal cursor operations }
  445. procedure TMouseManager.InitializeNormal;
  446. var TheMP : TPoint;
  447. begin
  448.   { Reset State Variables }
  449.   BitmapCursor := false;
  450.   IconCursor := false;
  451.   IsAnimated := false;
  452.   { Call API to get mouse coordinates }
  453.   GetCursorPos( TheMP );
  454.   { Store the coordinates for later use }
  455.   TheMX := TheMP.X;
  456.   TheMY := TheMP.Y;
  457.   Old_X := TheMX;
  458.   Old_Y := TheMY;
  459.   New_X := TheMX;
  460.   New_Y := TheMY;
  461. end;
  462.  
  463. { This procedure initializes a bitmap cursor }
  464. procedure TMouseManager.InitializeBitmap( TheBmp : TBitmap );
  465. begin
  466.   InitializeNormal;
  467.   CursorBMP := TheBMP;
  468.   BitmapCursor := true;
  469. end;
  470.  
  471. { This procedure initalizes an icon cursor }
  472. procedure TMouseManager.InitializeIcon( TheIcon : TIcon );
  473. begin
  474.   InitializeNormal;
  475.   CursorIcon := TheIcon;
  476.   IconCursor := true;
  477. end;
  478.  
  479. { This procedure initializes an animated icon cursor }
  480. procedure TMouseManager.InitializeAnimated( TheIcon : TIcon;
  481.            TheInterval : Integer; TheIconList : TList );
  482. begin
  483.   InitializeNormal;
  484.   CursorIcon := TheIcon;
  485.   IconCursor := true;
  486.   IsAnimated := true;
  487.   AnimationInterval := TheInterval;
  488.   TheAnimationList := TheIconList;
  489.   TheTimer := TTimer.Create( Self );
  490.   TheTimer.Enabled := false;
  491.   TheTimer.Interval := AnimationInterval;
  492.   TheTimer.OnTimer := TimerAction;
  493. end;
  494.  
  495. { This procedure returns the current stored mouse position }
  496. procedure TMouseManager.GetMousePosition( var MouseX , MouseY : Integer );
  497. begin
  498.   { Return stored position rather than call API }
  499.   MouseX := TheMX;
  500.   MouseY := TheMY;
  501. end;
  502.  
  503. { This procedure sets the Mouse Position internally }
  504. procedure TMouseManager.SetMousePosition( MouseX , MouseY : Integer );
  505. begin
  506.   { Set internal coordinates; don't call API }
  507.   TheMX := MouseX;
  508.   TheMY := MouseY;
  509. end;
  510.  
  511. { This procedure is used to drive the mouse with the keyboard }
  512. procedure TMouseManager.MoveSinglePixelLeft;
  513. begin
  514.   { Use internal coordinates and check for screen wrapping }
  515.   if TheMX > KBMJ_SINGLE then
  516.   begin
  517.     { Not wrapped; move along one unit to the left }
  518.     TheMX := TheMX - KBMJ_SINGLE;
  519.     SetCursorPos( TheMX , TheMY );
  520.   end
  521.   else
  522.   begin
  523.     { Wrapped; jump to right and move back one unit }
  524.     TheMX := Screen.Width - KBMJ_SINGLE;
  525.     SetCursorPos( TheMX , TheMY );
  526.   end;
  527. end;
  528.  
  529. { This procedure is used to drive the mouse with the keyboard }
  530. procedure TMouseManager.MoveSinglePixelRight;
  531. begin
  532.   { Use internal coordinates and check for screen wrapping }
  533.   if TheMX < ( Screen.Width - KBMJ_SINGLE ) then
  534.   begin
  535.     { Not wrapped; move along one unit to the right }
  536.     TheMX := TheMX + KBMJ_SINGLE;
  537.     SetCursorPos( TheMX , TheMY );
  538.   end
  539.   else
  540.   begin
  541.     { Wrapped; jump to left and move in one unit }
  542.     TheMX := KBMJ_SINGLE;
  543.     SetCursorPos( TheMX , TheMY );
  544.   end;
  545. end;
  546.  
  547. { This procedure is used to drive the mouse with the keyboard }
  548. procedure TMouseManager.MoveSinglePixelUp;
  549. begin
  550.   { Use internal coordinates and check for screen wrapping }
  551.   if TheMY > KBMJ_SINGLE then
  552.   begin
  553.     { Not wrapped; move along one unit to the top }
  554.     TheMY := TheMY - KBMJ_SINGLE;
  555.     SetCursorPos( TheMX , TheMY );
  556.   end
  557.   else
  558.   begin
  559.     { Wrapped; jump to bottom and move back one unit }
  560.     TheMY := Screen.Height - KBMJ_SINGLE;
  561.     SetCursorPos( TheMX , TheMY );
  562.   end;
  563. end;
  564.  
  565. { This procedure is used to drive the mouse with the keyboard }
  566. procedure TMouseManager.MoveSinglePixelDown;
  567. begin
  568.   { Use internal coordinates and check for screen wrapping }
  569.   if TheMY < ( Screen.Height - KBMJ_SINGLE ) then
  570.   begin
  571.     { Not wrapped; move along one unit to the bottom }
  572.     TheMY := TheMY + KBMJ_SINGLE;
  573.     SetCursorPos( TheMX , TheMY );
  574.   end
  575.   else
  576.   begin
  577.     { Wrapped; jump to top and move back one unit }
  578.     TheMY := KBMJ_SINGLE;
  579.     SetCursorPos( TheMX , TheMY );
  580.   end;
  581. end;
  582.  
  583. { This procedure is used to drive the mouse with the keyboard }
  584. procedure TMouseManager.MoveSmallJumpLeft;
  585. begin
  586.   { Use internal coordinates and check for screen wrapping }
  587.   if TheMX > KBMJ_SMALL then
  588.   begin
  589.     { Not wrapped; move along one unit to the left }
  590.     TheMX := TheMX - KBMJ_SMALL;
  591.     SetCursorPos( TheMX , TheMY );
  592.   end
  593.   else
  594.   begin
  595.     { Wrapped; jump to right and move back the unit }
  596.     TheMX := Screen.Width - KBMJ_SMALL;
  597.     SetCursorPos( TheMX , TheMY );
  598.   end;
  599. end;
  600.  
  601. { This procedure is used to drive the mouse with the keyboard }
  602. procedure TMouseManager.MoveSmallJumpRight;
  603. begin
  604.   { Use internal coordinates and check for screen wrapping }
  605.   if TheMX < ( Screen.Width - KBMJ_SMALL ) then
  606.   begin
  607.     { Not wrapped; move along one unit to the right }
  608.     TheMX := TheMX + KBMJ_SMALL;
  609.     SetCursorPos( TheMX , TheMY );
  610.   end
  611.   else
  612.   begin
  613.     { Wrapped; jump to left and move in one unit }
  614.     TheMX := KBMJ_SMALL;
  615.     SetCursorPos( TheMX , TheMY );
  616.   end;
  617. end;
  618.  
  619. { This procedure is used to drive the mouse with the keyboard }
  620. procedure TMouseManager.MoveSmallJumpUp;
  621. begin
  622.   { Use internal coordinates and check for screen wrapping }
  623.   if TheMY > KBMJ_SMALL then
  624.   begin
  625.     { Not wrapped; move along one unit to the top }
  626.     TheMY := TheMY - KBMJ_SMALL;
  627.     SetCursorPos( TheMX , TheMY );
  628.   end
  629.   else
  630.   begin
  631.     { Wrapped; jump to bottom and move back one unit }
  632.     TheMY := Screen.Height - KBMJ_SMALL;
  633.     SetCursorPos( TheMX , TheMY );
  634.   end;
  635. end;
  636.  
  637. { This procedure is used to drive the mouse with the keyboard }
  638. procedure TMouseManager.MoveSmallJumpDown;
  639. begin
  640.   { Use internal coordinates and check for screen wrapping }
  641.   if TheMY < ( Screen.Height - KBMJ_SMALL ) then
  642.   begin
  643.     { Not wrapped; move along one unit to the bottom }
  644.     TheMY := TheMY + KBMJ_SMALL;
  645.     SetCursorPos( TheMX , TheMY );
  646.   end
  647.   else
  648.   begin
  649.     { Wrapped; jump to top and move back one unit }
  650.     TheMY := KBMJ_SMALL;
  651.     SetCursorPos( TheMX , TheMY );
  652.   end;
  653. end;
  654.  
  655. { This procedure is used to drive the mouse with the keyboard }
  656. procedure TMouseManager.MoveLargeJumpLeft;
  657. begin
  658.   { Use internal coordinates and check for screen wrapping }
  659.   if TheMX > KBMJ_LARGE then
  660.   begin
  661.     { Not wrapped; move along the unit to the left }
  662.     TheMX := TheMX - KBMJ_LARGE;
  663.     SetCursorPos( TheMX , TheMY );
  664.   end
  665.   else
  666.   begin
  667.     { Wrapped; jump to right and move back the unit }
  668.     TheMX := Screen.Width - KBMJ_LARGE;
  669.     SetCursorPos( TheMX , TheMY );
  670.   end;
  671. end;
  672.  
  673. { This procedure is used to drive the mouse with the keyboard }
  674. procedure TMouseManager.MoveLargeJumpRight;
  675. begin
  676.   { Use internal coordinates and check for screen wrapping }
  677.   if TheMX < ( Screen.Width - KBMJ_LARGE ) then
  678.   begin
  679.     { Not wrapped; move along one unit to the right }
  680.     TheMX := TheMX + KBMJ_LARGE;
  681.     SetCursorPos( TheMX , TheMY );
  682.   end
  683.   else
  684.   begin
  685.     { Wrapped; jump to left and move in one unit }
  686.     TheMX := KBMJ_LARGE;
  687.     SetCursorPos( TheMX , TheMY );
  688.   end;
  689. end;
  690.  
  691. { This procedure is used to drive the mouse with the keyboard }
  692. procedure TMouseManager.MoveLargeJumpUp;
  693. begin
  694.   { Use internal coordinates and check for screen wrapping }
  695.   if TheMY > KBMJ_LARGE then
  696.   begin
  697.     { Not wrapped; move along one unit to the top }
  698.     TheMY := TheMY - KBMJ_LARGE;
  699.     SetCursorPos( TheMX , TheMY );
  700.   end
  701.   else
  702.   begin
  703.     { Wrapped; jump to bottom and move back one unit }
  704.     TheMY := Screen.Height - KBMJ_LARGE;
  705.     SetCursorPos( TheMX , TheMY );
  706.   end;
  707. end;
  708.  
  709. { This procedure is used to drive the mouse with the keyboard }
  710. procedure TMouseManager.MoveLargeJumpDown;
  711. begin
  712.   { Use internal coordinates and check for screen wrapping }
  713.   if TheMY < ( Screen.Height - KBMJ_LARGE ) then
  714.   begin
  715.     { Not wrapped; move along one unit to the bottom }
  716.     TheMY := TheMY + KBMJ_LARGE;
  717.     SetCursorPos( TheMX , TheMY );
  718.   end
  719.   else
  720.   begin
  721.     { Wrapped; jump to top and move back one unit }
  722.     TheMY := KBMJ_LARGE;
  723.     SetCursorPos( TheMX , TheMY );
  724.   end;
  725. end;
  726.  
  727. { This procedure sets up the bitmaps and global HDC prior to moving a }
  728. { Bitmap cursor.                                                      }
  729. procedure TMouseManager.StartBitmapCursor( TheX , TheY : Integer );
  730. var WorkingPoint1 ,
  731.     WorkingPoint2 : TPoint;
  732. begin
  733.   GlobalDC := GetDC( 0 );
  734.   WorkspaceBMP := TBitmap.Create;
  735.   WorkspaceBMP.Width := Screen.Width;
  736.   WorkSpaceBMP.Height := Screen.Height;
  737.   BitBlt( WorkspaceBMP.Canvas.Handle , 0 , 0 , Screen.Width , Screen.Height ,
  738.    GlobalDC , 0 , 0 , SrcCopy );
  739.   BackgroundBMP := TBitmap.Create;
  740.   BackgroundBMP.Width := CursorBMP.Width;
  741.   BackgroundBMP.Height := CursorBMP.Height;
  742.   New_X := TheX;
  743.   New_Y := TheY;
  744.   StoredCursor := Screen.Cursor;
  745.   Screen.Cursor := CR_NULL;
  746.   {Grab the background image}
  747.   WorkingPoint1.X := New_X - ( CursorBMP.Width div 2 );
  748.   WorkingPoint1.Y := New_Y - ( CursorBMP.Height div 2 );
  749.   WorkingPoint2.X := New_X + ( CursorBMP.Width - ( CursorBMP.Width div 2 ));
  750.   WorkingPoint2.Y := New_Y + ( CursorBMP.Height - ( CursorBMP.Height div 2 ));
  751.   BackgroundBmp.Canvas.CopyRect( Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ) ,
  752.    WorkspaceBMP.Canvas , Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X ,
  753.     WorkingPoint2.Y ));
  754.   {Put the cursor bitmap onto the workspace canvas}
  755.   with WorkspaceBMP.Canvas do
  756.   begin
  757.     CopyMode := cmSrcCopy;
  758.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  759.      CursorBMP.Canvas , Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ));
  760.   end;
  761.   {Copy the workspace bitmap onto the visible screen}
  762.     BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , CursorBMP.Width , CursorBMP.Height ,
  763.      WorkspaceBMP.Canvas.Handle , WorkingPoint1.X , WorkingPoint1.Y , SrcCopy );
  764.   Old_X := New_X;
  765.   Old_Y := New_Y;
  766. end;
  767.  
  768. { This procedure moves a bitmap cursor according to the imported New coords }
  769. procedure TMouseManager.MoveBitmapCursor( TheX , TheY : Integer );
  770. var StartX,
  771.     StartY,
  772.     XDiff,
  773.     YDiff : Integer;
  774.     WorkingPoint1 ,
  775.     WorkingPoint2  : TPoint;
  776. begin
  777.   New_X := TheX;
  778.   New_Y := TheY;
  779.   WorkingPoint1.X := Old_X - ( CursorBMP.Width div 2 );
  780.   WorkingPoint1.Y := Old_Y - ( CursorBMP.Height div 2 );
  781.   WorkingPoint2.X := Old_X + ( CursorBMP.Width - ( CursorBMP.Width div 2 ));
  782.   WorkingPoint2.Y := Old_Y + ( CursorBMP.Height - ( CursorBMP.Height div 2 ));
  783.   with WorkspaceBMP.Canvas do
  784.   begin
  785.     CopyMode := cmSrcCopy;
  786.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  787.       BackgroundBMP.Canvas , Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ));
  788.   end;
  789.   {Put the saved bitmap onto the workspace canvas}
  790.   with WorkspaceBMP.Canvas do
  791.   begin
  792.     CopyMode := cmSrcCopy;
  793.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  794.      BackgroundBMP.Canvas , Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ));
  795.   end;
  796.   {Grab the background image}
  797.   WorkingPoint1.X := New_X - ( CursorBMP.Width div 2 );
  798.   WorkingPoint1.Y := New_Y - ( CursorBMP.Height div 2 );
  799.   WorkingPoint2.X := New_X + ( CursorBMP.Width - ( CursorBMP.Width div 2 ));
  800.   WorkingPoint2.Y := New_Y + ( CursorBMP.Height - ( CursorBMP.Height div 2 ));
  801.   BackgroundBmp.Canvas.CopyRect( Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ) ,
  802.    WorkspaceBMP.Canvas , Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X ,
  803.     WorkingPoint2.Y ));
  804.   {Put the cursor bitmap onto the workspace canvas}
  805.   with WorkspaceBMP.Canvas do
  806.   begin
  807.     CopyMode := cmSrcCopy;
  808.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  809.      CursorBMP.Canvas , Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ));
  810.   end;
  811.   {Copy the workspace bitmap onto the visible screen}
  812.   if New_X > Old_X then StartX := Old_X else StartX := New_X;
  813.   if New_Y > Old_Y then StartY := Old_Y else StartY := New_Y;
  814.   XDiff := Abs( Old_X - New_X );
  815.   YDiff := Abs( Old_Y - New_Y );
  816.   {Grab the background image}
  817.   WorkingPoint1.X := StartX - ( CursorBMP.Width div 2 );
  818.   WorkingPoint1.Y := StartY - ( CursorBMP.Height div 2 );
  819.   BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , CursorBMP.Width + XDiff ,
  820.    CursorBMP.Height + YDiff , WorkspaceBMP.Canvas.Handle , WorkingPoint1.X ,
  821.     WorkingPoint1.Y , SrcCopy );
  822.   Old_X := New_X;
  823.   Old_Y := New_Y;
  824. end;
  825.  
  826. { This procedure releases a bitmap cursor and frees its DC }
  827. procedure TMouseManager.EndBitmapCursor( TheX , TheY : Integer );
  828. var WorkingPoint1 ,
  829.     WorkingPoint2 : TPoint;
  830. begin
  831.   BitmapCursor := false;
  832.   WorkingPoint1.X := Old_X - ( CursorBMP.Width div 2 );
  833.   WorkingPoint1.Y := Old_Y - ( CursorBMP.Height Div 2 );
  834.   WorkingPoint2.X := Old_X + ( CursorBMP.Width - ( CursorBMP.Width div 2 ));
  835.   WorkingPoint2.Y := Old_Y + ( CursorBMP.Height - ( CursorBMP.Height div 2 ));
  836.   {Put the saved bitmap onto the workspace canvas}
  837.   with WorkspaceBMP.Canvas do
  838.   begin
  839.     CopyMode := cmSrcCopy;
  840.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  841.        BackGroundBMP.Canvas , Rect( 0 , 0 , CursorBMP.Width ,  CursorBMP.Height ));
  842.   end;
  843.   {Copy the workspace bitmap onto the visible screen}
  844.   BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , CursorBMP.Width , CursorBMP.Height ,
  845.    WorkspaceBMP.Canvas.handle , WorkingPoint1.X , WorkingPoint1.Y , SrcCopy );
  846.   ReleaseDC( 0 , GlobalDC );
  847.   Screen.Cursor := StoredCursor;
  848. end;
  849.  
  850. { This procedure starts the process of displaying an icon cursor }
  851. procedure TMouseManager.StartIconCursor( TheX , TheY : Integer );
  852. var WorkingPoint1 ,
  853.     WorkingPoint2 : TPoint;
  854. begin
  855.   GlobalDC := GetDC( 0 );
  856.   WorkspaceBMP := TBitmap.Create;
  857.   WorkspaceBMP.Width := Screen.Width;
  858.   WorkSpaceBMP.Height := Screen.Height;
  859.   BitBlt( WorkspaceBMP.Canvas.Handle , 0 , 0 , Screen.Width , Screen.Height ,
  860.    GlobalDC , 0 , 0 , SrcCopy );
  861.   BackgroundBMP := TBitmap.Create;
  862.   BackgroundBMP.Width := 33;
  863.   BackgroundBMP.Height := 33;
  864.   New_X := TheX;
  865.   New_Y := TheY;
  866.   StoredCursor := Screen.Cursor;
  867.   Screen.Cursor := CR_NULL;
  868.   {Grab the background image}
  869.   WorkingPoint1.X := New_X - 16;
  870.   WorkingPoint1.Y := New_Y - 16;
  871.   WorkingPoint2.X := New_X + 17;
  872.   WorkingPoint2.Y := New_Y + 17;
  873.   BackgroundBmp.Canvas.CopyRect( Rect( 0 , 0 , 33 , 33 ) , WorkspaceBMP.Canvas ,
  874.      Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ));
  875.   {Put the icon onto the workspace canvas}
  876.   with WorkspaceBMP.Canvas do
  877.   begin
  878.     Draw( WorkingPoint1.X , WorkingPoint1.Y , CursorIcon );
  879.   end;
  880.   {Copy the workspace bitmap onto the visible screen}
  881.     BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , 33 , 33 ,
  882.      WorkspaceBMP.Canvas.Handle , WorkingPoint1.X , WorkingPoint1.Y , SrcCopy );
  883.   Old_X := New_X;
  884.   Old_Y := New_Y;
  885. end;
  886.  
  887. { This procedure moves the icon cursor in response to mouse moves }
  888. procedure TMouseManager.MoveIconCursor( TheX , TheY : Integer );
  889. var StartX,
  890.     StartY,
  891.     XDiff,
  892.     YDiff : Integer;
  893.     WorkingPoint1 ,
  894.     WorkingPoint2  : TPoint;
  895. begin
  896.   New_X := TheX;
  897.   New_Y := TheY;
  898.   {Put the saved bitmap onto the workspace canvas}
  899.   WorkingPoint1.X := Old_X - 16;
  900.   WorkingPoint1.Y := Old_Y - 16;
  901.   WorkingPoint2.X := Old_X + 17;
  902.   WorkingPoint2.Y := Old_Y + 17;
  903.   with WorkspaceBMP.Canvas do
  904.   begin
  905.     CopyMode := cmSrcCopy;
  906.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  907.       BackgroundBMP.Canvas , Rect( 0 , 0 , 33 , 33 ));
  908.   end;
  909.   {Grab the background image}
  910.   WorkingPoint1.X := New_X - 16;
  911.   WorkingPoint1.Y := New_Y - 16;
  912.   WorkingPoint2.X := New_X + 17;
  913.   WorkingPoint2.Y := New_Y + 17;
  914.   BackgroundBMP.Canvas.CopyRect( Rect( 0 , 0 , 33 , 33 ) , WorkspaceBMP.Canvas ,
  915.      Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ));
  916.   {Put the icon onto the workspace canvas}
  917.   with WorkspaceBMP.Canvas do
  918.   begin
  919.     Draw( WorkingPoint1.X , WorkingPoint1.Y , CursorIcon );
  920.   end;
  921.   {Copy the workspace bitmap onto the visible screen}
  922.     if New_X > Old_X then StartX := Old_X else StartX := New_X;
  923.     if New_Y > Old_Y then StartY := Old_Y else StartY := New_Y;
  924.     XDiff := Abs( Old_X - New_X );
  925.     YDiff := Abs( Old_Y - New_Y );
  926.     {Grab the background image}
  927.     WorkingPoint1.X := StartX - 16;
  928.     WorkingPoint1.Y := StartY - 16;
  929.     BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , 33 + XDiff , 33 + YDiff ,
  930.      WorkspaceBMP.Canvas.Handle , WorkingPoint1.X , WorkingPoint1.Y , SrcCopy );
  931.   Old_X := New_X;
  932.   Old_Y := New_Y;
  933. end;
  934.  
  935. { This procedure ends the icon cursor movement and frees its DCs }
  936. procedure TMouseManager.EndIconCursor( TheX , TheY : Integer );
  937. var WorkingPoint1 ,
  938.     WorkingPoint2 : TPoint;
  939. begin
  940.   IconCursor := false;
  941.   WorkingPoint1.X := Old_X - 16;
  942.   WorkingPoint1.Y := Old_Y - 16;
  943.   WorkingPoint2.X := Old_X + 17;
  944.   WorkingPoint2.Y := Old_Y + 17;
  945.   {Put the saved bitmap onto the workspace canvas}
  946.   with WorkspaceBMP.Canvas do
  947.   begin
  948.     CopyMode := cmSrcCopy;
  949.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  950.        BackGroundBMP.Canvas , Rect( 0 , 0 , 33 ,  33 ));
  951.   end;
  952.   {Copy the workspace bitmap onto the visible screen}
  953.   BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , 33 , 33 ,
  954.    WorkspaceBMP.Canvas.handle , WorkingPoint1.X , WorkingPoint1.Y , SrcCopy );
  955.   ReleaseDC( 0 , GlobalDC );
  956.   Screen.Cursor := StoredCursor;
  957. end;
  958.  
  959. { This procedure starts the animated icon cursor }
  960. procedure TMouseManager.StartAnimatedIconCursor( TheX , TheY : Integer );
  961. begin
  962.   StartIconCursor( TheX , TheY );
  963.   TheTimer.Enabled := true;
  964.   CurrentAnimationPointer := 1;
  965. end;
  966.  
  967. { This procedue ends the animated icon cursor }
  968. procedure TMouseManager.EndAnimatedIconCursor( TheX , TheY : Integer );
  969. begin
  970.   EndIconCursor( TheX , TheY );
  971.   TheTimer.Enabled := false;
  972.   CursorIcon := TIcon( TheAnimationList[ 0 ] );
  973. end;
  974.  
  975. { This procedure moves the animated icon cursor }
  976. procedure TMouseManager.MoveAnimatedIconCursor( TheX , TheY : Integer );
  977. begin
  978.   MoveIconCursor( TheX , TheY );
  979. end;
  980.  
  981. { This procedure switches icons on timer events and prompts a redraw }
  982. procedure TMouseManager.TimerAction( Sender : TObject );
  983. begin
  984.   Inc( CurrentAnimationPointer );     
  985.   if CurrentAnimationPointer > TheAnimationList.Count then
  986.    CurrentAnimationPointer := 1;
  987.   CursorIcon := TIcon( TheAnimationList[ CurrentAnimationPointer - 1 ] );
  988.   MoveIconCursor( Old_X , Old_Y );
  989. end;
  990.  
  991. { This function returns true if CAPSLOCK is down }
  992. function TIoManager.IsCapsLockDown : Boolean;
  993. begin
  994.   if CLState then result := true else result := false;
  995. end;
  996.  
  997. { This function returns true if NUMLOCK is down }
  998. function TIoManager.ISNumLockDown : Boolean;
  999. begin
  1000.   if NLState then result := true else result := false;
  1001. end;
  1002.  
  1003. { This function returns true if SCROLLLOCK is down }
  1004. function TIoManager.IsScrollLockDown : Boolean;
  1005. begin
  1006.   if SLState then result := true else result := false;
  1007. end;
  1008.  
  1009. { this function gets the values for CLState, NLState, and SLState }
  1010. procedure TIoManager.InitLocks;
  1011. var TheKeys : TKeyboardState;
  1012. begin
  1013.   GetKeyBoardState( TheKeys );
  1014.   CLState := (( TheKeys[ VK_Capital ] mod 2 ) = 1 );
  1015.   NLState := (( TheKeys[ VK_Numlock ] mod 2 ) = 1 );
  1016.   CLState := (( TheKeys[ VK_Scroll ] mod 2 ) = 1 );
  1017. end;
  1018.  
  1019. { This procedure returns the state of the three lock variables }
  1020. procedure TIoManager.ReadLocks( var TheCL , TheNL , TheSL : Boolean );
  1021. begin
  1022.   TheCL := CLState;
  1023.   TheNL := NLState;
  1024.   TheSL := SLState;
  1025. end;
  1026.  
  1027. { This procedure sets the state of the three lock variables to the imported vals }
  1028. procedure TIoManager.SetLocks( TheCL , TheNL , TheSL : Boolean );
  1029. var TheKeys : TKeyBoardState;
  1030. begin
  1031.   GetKeyBoardState( TheKeys );
  1032.   CLState := TheCL;
  1033.   NLState := TheNL;
  1034.   SLState := TheSL;
  1035.   if ClState then TheKeys[ VK_Capital ] := 1 else
  1036.    TheKeys[ VK_Capital ] := 0;
  1037.   if NLState then TheKeys[ VK_Numlock ] := 1 else
  1038.    TheKeys[ VK_Numlock ] := 0;
  1039.   if SLState then TheKeys[ VK_Scroll ] := 1 else
  1040.    TheKeys[ VK_Scroll ] := 0;
  1041.   SetKeyBoardState( TheKeys );
  1042. end;
  1043.  
  1044. { This procedure handles pressing of F1 for CCFileManagerForm }
  1045. procedure TIoManager.OnF1Pressed(Sender: TObject; var Key: Word;
  1046.   Shift: TShiftState);
  1047. begin
  1048.   MessageDlg( 'Help not implemented!' , mtInformation,[mbok],0);
  1049. end;
  1050.  
  1051. { This procedure handles pressing of F2 for CCFileManagerForm }
  1052. procedure TIoManager.OnF2Pressed(Sender: TObject; var Key: Word;
  1053.   Shift: TShiftState);
  1054. begin
  1055.   TCCFileMgrForm( Parent ).BitBtn1Click( Sender );
  1056. end;
  1057.  
  1058. { This procedure handles pressing of F3 for CCFileManagerForm }
  1059. procedure TIoManager.OnF3Pressed(Sender: TObject; var Key: Word;
  1060.   Shift: TShiftState);
  1061. begin
  1062.   TCCFileMgrForm( Parent ).BitBtn2Click( Sender );
  1063. end;
  1064.  
  1065. { This procedure handles pressing of F4 for CCFileManagerForm }
  1066. procedure TIoManager.OnF4Pressed(Sender: TObject; var Key: Word;
  1067.   Shift: TShiftState);
  1068. begin
  1069.   TCCFileMgrForm( Parent ).BitBtn3Click( Sender );
  1070. end;
  1071.  
  1072. { This procedure handles pressing of F5 for CCFileManagerForm }
  1073. procedure TIoManager.OnF5Pressed(Sender: TObject; var Key: Word;
  1074.   Shift: TShiftState);
  1075. begin
  1076.   TCCFileMgrForm( Parent ).BitBtn4Click( Sender );
  1077. end;
  1078.  
  1079. { This procedure handles pressing of F6 for CCFileManagerForm }
  1080. procedure TIoManager.OnF6Pressed(Sender: TObject; var Key: Word;
  1081.   Shift: TShiftState);
  1082. begin
  1083.   TCCFileMgrForm( Parent ).BitBtn5Click( Sender );
  1084. end;
  1085.  
  1086. { This procedure handles pressing of F7 for CCFileManagerForm }
  1087. procedure TIoManager.OnF7Pressed(Sender: TObject; var Key: Word;
  1088.   Shift: TShiftState);
  1089. begin
  1090.   TCCFileMgrForm( Parent ).BitBtn9Click( Sender );
  1091. end;
  1092.  
  1093. { This procedure handles pressing of F8 for CCFileManagerForm }
  1094. procedure TIoManager.OnF8Pressed(Sender: TObject; var Key: Word;
  1095.   Shift: TShiftState);
  1096. begin
  1097.   TCCFileMgrForm( Parent ).BitBtn6Click( Sender );
  1098. end;
  1099.  
  1100. { This procedure handles pressing of F9 for CCFileManagerForm }
  1101. procedure TIoManager.OnF9Pressed(Sender: TObject; var Key: Word;
  1102.   Shift: TShiftState);
  1103. begin
  1104.   TCCFileMgrForm( Parent ).BitBtn11Click( Sender );
  1105. end;
  1106.  
  1107. { This procedure handles pressing of F10 for CCFileManagerForm }
  1108. procedure TIoManager.OnF10Pressed(Sender: TObject; var Key: Word;
  1109.   Shift: TShiftState);
  1110. begin
  1111.   TCCFileMgrForm( Parent ).BitBtn7Click( Sender );
  1112. end;
  1113.  
  1114. { This procedure handles pressing of F11 for CCFileManagerForm }
  1115. procedure TIoManager.OnF11Pressed(Sender: TObject; var Key: Word;
  1116.   Shift: TShiftState);
  1117. begin
  1118.   TCCFileMgrForm( Parent ).BitBtn8Click( Sender );
  1119. end;
  1120.  
  1121. { This procedure handles pressing of F12 for CCFileManagerForm }
  1122. procedure TIoManager.OnF12Pressed(Sender: TObject; var Key: Word;
  1123.   Shift: TShiftState);
  1124. begin
  1125.   TCCFileMgrForm( Parent ).BitBtn10Click( Sender );
  1126. end;
  1127.  
  1128. { Returns True if the Left Button was pressed in the last mouse operation }
  1129. function TIOManager.WasLeftPressed : Boolean;
  1130. begin
  1131.   if ( mbLeft = WhichButton ) then WasLeftPressed := true else
  1132.    WasLeftPressed := false;
  1133. end;
  1134.  
  1135. { Returns true if the Right Button was pressed in the last mouse operation }
  1136. function TIOManager.WasRightPressed : Boolean;
  1137. begin
  1138.   if mbRight = WhichButton then WasRightPressed := true else
  1139.    WasRightPressed := false;
  1140. end;
  1141.  
  1142. { Returns true if the Middle Button was pressed in the last mouse operation }
  1143. function TIOManager.WasMiddlePressed : Boolean;
  1144. begin
  1145.   if mbMiddle = WhichButton then WasMiddlePressed := true else
  1146.    WasMiddlePressed := false;
  1147. end;
  1148.  
  1149. { Returns true if the ALT key was down during the last IO operation }
  1150. function TIOManager.WasALTPressed : Boolean;
  1151. begin
  1152.   if ssAlt in WhichState then WasALTPressed := true else
  1153.    WasALTPressed := false;
  1154. end;
  1155.  
  1156. { Returns true if either SHIFT key was down during the last IO operation }
  1157. function TIOManager.WasSHIFTPressed : Boolean;
  1158. begin
  1159.   if ssShift in WhichState then WasSHIFTPressed := true else
  1160.    WasSHIFTPressed := false;
  1161. end;
  1162.  
  1163. { Returns true if the Control Key was down during the last IO operation }
  1164. function TIOManager.WasCTRLPressed : Boolean;
  1165. begin
  1166.   if ssCtrl in WhichState then WasCTRLPressed := true else
  1167.    WasCTRLPressed := false;
  1168. end;
  1169.  
  1170.  
  1171. { This procedure does a fully error-trapped change directory }
  1172. procedure TFileWorkBench.ChangeTheDirectory( NewPath : String );
  1173. var CurrentDirectory : String;
  1174. begin
  1175.   if NewPath = '..' then
  1176.   begin { Back up one level }
  1177.     {$I+}
  1178.     try
  1179.       { Find the current directory }
  1180.       GetDir( 0 , CurrentDirectory );
  1181.       { Use EFP to move up one level }
  1182.       CurrentDirectory := ExtractFilePath( CurrentDirectory );
  1183.       { Strip trailing \ if not root }
  1184.       CurrentDirectory := StripNonRootTrailingBackSlash( CurrentDirectory );
  1185.       { Try the change to the New drive }
  1186.       ChDir( CurrentDirectory );
  1187.     except
  1188.       { if any exception occurs instantiate exception and show }
  1189.       On E:EInOutError do
  1190.       begin
  1191.         { Call custom error display/lookup procedure }
  1192.         HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  1193.          E.Message , E.ErrorCode );
  1194.       end;
  1195.     end;
  1196.   end
  1197.   else
  1198.   begin { Change to explicit path }
  1199.     {$I+}
  1200.     try
  1201.       { Get target directory path }
  1202.       CurrentDirectory := NewPath;
  1203.       { Strip trailing \ if not root }
  1204.       CurrentDirectory := StripNonRootTrailingBackSlash( CurrentDirectory );
  1205.       { Try the change to the New drive }
  1206.       ChDir( CurrentDirectory );
  1207.     except
  1208.       { if any exception occurs instantiate exception and show }
  1209.       On E:EInOutError do
  1210.       begin
  1211.         { Call custom error display/lookup procedure }
  1212.         HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  1213.          E.Message , E.ErrorCode );
  1214.       end;
  1215.     end;
  1216.   end;
  1217. end;
  1218.  
  1219. { This procedure does a fully error-trapped change directory }
  1220. procedure TFileWorkBench.ChangeTheDriveAndDirectory( NewDrive : Integer );
  1221. var CurrentDirectory : String;
  1222. begin
  1223.   {$I+}
  1224.   try
  1225.     { Find the working directory on New drive }
  1226.     GetDir( NewDrive , CurrentDirectory );
  1227.     { Try the change to the New drive }
  1228.     ChDir( CurrentDirectory );
  1229.   except
  1230.     { if any exception occurs instantiate exception and show }
  1231.     On E:EInOutError do
  1232.     begin
  1233.       { Call custom error display/lookup procedure }
  1234.       HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  1235.        E.Message , E.ErrorCode );
  1236.     end;
  1237.   end;
  1238. end;
  1239.  
  1240. { This procedure copies a single file with error trapping }
  1241. procedure TFileWorkBench.CopyTheFile( OldPath , NewPath : String );
  1242. var AResult : Boolean; { Internal data flag }
  1243. begin
  1244.   { If Copyfile returns false an error occurred }
  1245.   AResult := CopyFile( OldPath , NewPath +
  1246.    ExtractFileName( OldPath ));
  1247.   { Display meaningful error message }
  1248.   if not AResult then HandleDOSError( GlobalErrorType , OldPath, GlobalError );
  1249. end;
  1250.  
  1251. { This procedure moves a file by copying and delete it }
  1252. procedure TFileWorkBench.MoveTheFile( OldPath , NewPath : String );
  1253. var AResult : Boolean; { Internal data flag }
  1254.     TheFile : File;    { Use to get errors  }
  1255. begin
  1256.   { If Copyfile returns false an error occurred }
  1257.   AResult := CopyFile( OldPath , NewPath +
  1258.     ExtractFileName( OldPath ));
  1259.   { Display meaningful error message }
  1260.   if not AResult then HandleDOSError( GlobalErrorType ,
  1261.     OldPath , GlobalError );
  1262.   { After valid copying, delete source file }
  1263.   {$I+}
  1264.   if AResult then try
  1265.     { Use this trick to get valid exception handling }
  1266.     AssignFile( TheFile , OldPath );
  1267.     { Use erase because Deletefile doesn't give exceptions! }
  1268.     Erase( TheFile );
  1269.   except
  1270.     { if any exception occurs instantiate exception and show }
  1271.     On E:EInOutError do
  1272.     begin
  1273.       { Call custom error display/lookup procedure }
  1274.       HandleIOException( EOC_DELETEFILE , OldPath ,
  1275.        E.Message , E.ErrorCode );
  1276.     end;
  1277.   end;
  1278. end;
  1279.  
  1280. { This procedure safely deletes a single file }
  1281. procedure TFileWorkBench.DeleteTheFile( ThePath : String );
  1282. var TheFile : File; { Internal file handle }
  1283. begin
  1284.   {$I+}
  1285.   try
  1286.     { Use this trick to get valid exception handling }
  1287.     AssignFile( TheFile , ThePath );
  1288.     { Use erase because Deletefile doesn't give exceptions! }
  1289.     Erase( TheFile );
  1290.   except
  1291.     { if any exception occurs instantiate exception and show }
  1292.     On E:EInOutError do
  1293.     begin
  1294.       { Call custom error display/lookup procedure }
  1295.       HandleIOException( EOC_DELETEFILE , ThePath ,
  1296.        E.Message , E.ErrorCode );
  1297.     end;
  1298.   end;
  1299. end;
  1300.  
  1301. { This procedure renames a file with full error trapping }
  1302. procedure TFileWorkBench.RenameTheFile( OldPath , NewName : String );
  1303. var TheFile : File; { Internal file handle }
  1304. begin
  1305.   {$I+}
  1306.   try
  1307.     { Use this trick to get valid exception handling }
  1308.     AssignFile( TheFile , OldPath );
  1309.     { Use this because RenameFile doesn't give exceptions! }
  1310.     Rename( TheFile , NewName );
  1311.   except
  1312.     { if any exception occurs instantiate exception and show }
  1313.     On E:EInOutError do
  1314.     begin
  1315.       { Call custom error display/lookup procedure }
  1316.       HandleIOException( EOC_RENAMEFILE , OldPath  ,
  1317.        E.Message , E.ErrorCode );
  1318.     end;
  1319.   end;
  1320. end;
  1321.  
  1322. { This procedure creates a New directory with full error trapping }
  1323. procedure TFileWorkBench.CreateNewDirectory( NewPath : String );
  1324. begin
  1325.   {$I+}
  1326.   try
  1327.     Mkdir( NewPath );
  1328.   except
  1329.     { if any exception occurs instantiate exception and show }
  1330.     On E:EInOutError do
  1331.     begin
  1332.       { Call custom error display/lookup procedure }
  1333.       HandleIOException( EOC_MAKEDIR , NewPath  ,
  1334.        E.Message , E.ErrorCode );
  1335.     end;
  1336.   end;
  1337. end;
  1338.  
  1339. { This procedure remove a directory with full error trapping }
  1340. procedure TFileWorkBench.RemoveDirectory( ThePath : String );
  1341. begin
  1342.   {$I+}
  1343.   try
  1344.     Rmdir( ThePath );
  1345.   except
  1346.     { if any exception occurs instantiate exception and show }
  1347.     On E:EInOutError do
  1348.     begin
  1349.       { Call custom error display/lookup procedure }
  1350.       HandleIOException( EOC_DELETEDIR , ThePath  ,
  1351.        E.Message , E.ErrorCode );
  1352.     end;
  1353.   end;
  1354. end;
  1355.  
  1356. { Use this to set the attributes of a file with error trapping }
  1357. procedure TFileWorkBench.SetFileAttributes( TheFile  : String;
  1358.            TheAttributes : Integer );
  1359. var TheResult : Integer; { Holds error code if any }
  1360. begin
  1361.   { Attempt to set the attributes }
  1362.   TheResult := FileSetAttr( TheFile , TheAttributes );
  1363.   { if negative number error, so signal }
  1364.   if TheResult < 0 then
  1365.    HandleDOSError( EOC_SETATTR , TheFile , -TheResult );
  1366. end;
  1367.  
  1368. { This procedure recursively copies a directory to a New path }
  1369. procedure TFileWorkBench.RecursivelyCopyDirectory( OldPath , NewPath : String );
  1370. var TheDir : String; { Holds source directory }
  1371. begin
  1372.   { Get the source directory to copy }
  1373.   TheDir := ExtractFileName( OldPath );
  1374.   { Force a backslash to the Newpath variable }
  1375.   NewPath := ForceTrailingBackSlash( NewPath );
  1376.   { Add the source directory to the target path }
  1377.   NewPath := NewPath + TheDir;
  1378.   { Create a New directory with the New name }
  1379.   CreateNewDirectory( NewPath );
  1380.   { Force a backslash for compatibility }
  1381.   NewPath := FOrcetrailingBackSlash( NewPath );
  1382.   { Do the recursive call }
  1383.   HandleRecursiveAction( OldPath , NewPath , FAC_COPY );
  1384. end;
  1385.  
  1386. { This procedure recursively moves a directory tree }
  1387. procedure TFileWorkBench.RecursivelyMoveDirectory( OldPath , NewPath : String );
  1388. var TheDir    : String; { Holds source directory  }
  1389.     SavedPath : String; { Holds saved dir to kill }
  1390. begin
  1391.   { Get the source directory to move }
  1392.   TheDir := ExtractFileName( OldPath );
  1393.   { Force a backslash to the Newpath variable }
  1394.   NewPath := ForceTrailingBackSlash( NewPath );
  1395.   { Save the starting path just in case }
  1396.   SavedPath := OldPath;
  1397.   { Add the source directory to the target path }
  1398.   NewPath := NewPath + TheDir;
  1399.   { Create a New directory with the New name }
  1400.   CreateNewDirectory( NewPath );
  1401.   { Force a backslash for compatibility }
  1402.   NewPath := FOrcetrailingBackSlash( NewPath );
  1403.   { Do the recursive call }
  1404.   HandleRecursiveAction( OldPath , NewPath , FAC_MOVE );
  1405.   { Remove the source directory }
  1406.   RemoveDirectory( SavedPath );
  1407. end;
  1408.  
  1409. { This procedure handles recursively deleting an entire directory tree }
  1410. procedure TFileWorkBench.RecursivelyDeleteDirectory( ThePath : String );
  1411. begin
  1412.   HandleRecursiveAction( ThePath , '' , FAC_DELETE );
  1413. end;
  1414.  
  1415.  
  1416. { This is the generic routine to copy, move, and delete whole directory trees }
  1417. procedure TFileWorkBench.HandleRecursiveAction( StartingPath , NewPath : String;
  1418.            ActionCode : Integer );
  1419. { VITAL!!! These variables MUST be local for recursrion to work! }
  1420. var
  1421.     Finished        : Boolean;         { Loop flag              }
  1422.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  1423.     TheResult       : Integer;         { return variable        }
  1424.     TargetPath ,
  1425.     FileMask   ,
  1426.     TheWorkingDirectory ,
  1427.     TheStoredWorkingDirectory ,
  1428.     ModifiedDirectory  : String;       { path for FF/FN         }
  1429.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  1430.     ButtonColor   ,                    { main panel color       }
  1431.     ButtonHLColor ,                    { bright panel color     }
  1432.     ButtonSColor  ,                    { dark panel color       }
  1433.     Textcolor       : TColor;          { label text color       }
  1434.     TheFile         : File;
  1435.  
  1436. begin
  1437.   { Set up the initial variables }
  1438.   Finished := false;
  1439.   TheWorkingDirectory := StartingPath;
  1440.   TheStoredWorkingDirectory := TheWorkingDirectory;
  1441.   TheWorkingDirectory := TheWorkingDirectory + '\*.*';
  1442.   TargetPath := ExtractFilePath( TheWorkingDirectory );
  1443.   { Make the call to FindFirst set to get any file }
  1444.   TheResult := FindFirst( TheWorkingDirectory , faAnyFile , TheSR );
  1445.   { loop through all files in the directory and delete them }
  1446.   while not Finished do
  1447.   begin
  1448.     { Make call to FindNext, using only SearchRecord from FindFirst }
  1449.     TheResult := FindNext( TheSR );
  1450.     { A -1 result means no more files so exit }
  1451.     if TheResult <> 0 then finished := true else
  1452.     begin
  1453.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  1454.        <> faDirectory ) then
  1455.       begin { A File }
  1456.         case ActionCode of
  1457.           FAC_COPY :
  1458.               begin
  1459.                 CopyTheFile( TargetPath + TheSR.Name , NewPath );
  1460.               end;
  1461.           FAC_MOVE :
  1462.               begin
  1463.                 MoveTheFile( TargetPath + TheSR.Name , NewPath );
  1464.               end;
  1465.           FAC_DELETE :
  1466.               begin { Delete }
  1467.                 if MessageDlg( 'Delete file ' + TargetPath + TheSR.Name + '?',
  1468.                    mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1469.                     DeleteTheFile( TargetPath + TheSR.Name );
  1470.               end;
  1471.         end;
  1472.       end;
  1473.     end;
  1474.   end;
  1475.   { Set up the variables to do recursive calls on all directories}
  1476.   Finished := false;
  1477.   ModifiedDirectory := TheStoredWorkingdirectory + '\*.*';
  1478.   { Make the call to FindFirst set to get any file, ignore result }
  1479.   TheResult := FindFirst( ModifiedDirectory , faDirectory , TheSR );
  1480.   while not Finished do
  1481.   begin
  1482.     { Make call to FindNext, using only SearchRecord from FindFirst }
  1483.     TheResult := FindNext( TheSR );
  1484.     { A -1 result means no more files so exit }
  1485.     if TheResult <> 0 then
  1486.       finished := true
  1487.     else
  1488.     begin
  1489.       if TheSR.Name <> '..' then { Ignore backup in this case }
  1490.       begin
  1491.         if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  1492.          = faDirectory ) then
  1493.         begin
  1494.           { Send in the New directory name }
  1495.           ModifiedDirectory := TheStoredWorkingDirectory  + '\' +
  1496.            TheSR.Name;
  1497.           { Reproduce directory structure for recursion in copy/move }
  1498.           NewPath := NewPath + TheSR.Name;
  1499.           case ActionCode of
  1500.             FAC_COPY , FAC_MOVE :
  1501.                begin { Create ahead for move and copy }
  1502.                  { Make the New directory for moving and copying }
  1503.                  CreateNewDirectory( NewPath );
  1504.                  { Force a backslash for compatibility }
  1505.                  NewPath := ForceTrailingBackSlash( NewPath );
  1506.                end;
  1507.             FAC_DELETE :
  1508.                begin  { No prior action needed for Delete }
  1509.                end;
  1510.           end;
  1511.           { Do the recursive call }
  1512.           HandleRecursiveAction( ModifiedDirectory , NewPath , ActionCode );
  1513.           case ActionCode of
  1514.             FAC_COPY :
  1515.                begin { no action for copy }
  1516.                end;
  1517.             FAC_MOVE , FAC_DELETE :
  1518.                begin  { Delete }
  1519.                  { Get a confirmation }
  1520.                  if MessageDlg( 'Remove Directory ' + TargetPath + TheSR.Name
  1521.                   + '?', mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1522.                    RemoveDirectory( TargetPath + TheSR.Name );
  1523.                end;
  1524.           end;
  1525.         end;
  1526.       end;
  1527.     end;
  1528.   end;
  1529. end;
  1530.  
  1531. { This is a generic copy routine taken from Delphi sample code }
  1532. { This function calls the sample Copy code and handles errors }
  1533. function TFileWorkBench.CopyFile( TargetPath ,
  1534.           DestinationPath : String ) : Boolean;
  1535. begin
  1536.   { Set global error value to no error }
  1537.   GlobalError := 0;
  1538.   { Call the sample procedure to do the copy }
  1539.   FMXUCopyFile( TargetPath, DestinationPath , GlobalErrorType , GlobalError );
  1540.   { If no error return true else return false }
  1541.   if GlobalError < 0 then CopyFile := false else
  1542.    CopyFile := true;
  1543. end;
  1544.  
  1545. { This procedure handles displaying a user-friendly Dialog box with a }
  1546. { Message for Delphi IO exception errors.                             }
  1547. procedure TFileWorkBench.HandleIOException( TheOpCode : Integer;
  1548.            ThePath : String; TheMessage : String; TheCode : Integer );
  1549. var ErrorMessageString : String;  { Holds internal data }
  1550.     OperationString    : String;  { Holds internal data }
  1551. begin
  1552.   { clear to check for unrecognized code }
  1553.   ErrorMessageString := '';
  1554.   { Check against imported code }
  1555.   case TheCode of
  1556.     2    : ErrorMessageString := 'File not found';
  1557.     3    : ErrorMessageString := 'Path not found';
  1558.     4    : ErrorMessageString := 'Too many open files';
  1559.     5    : ErrorMessageString := 'File access denied';
  1560.     6    : ErrorMessageString := 'Invalid file handle';
  1561.     12    : ErrorMessageString := 'Invalid file access code';
  1562.     15    : ErrorMessageString := 'Invalid drive number';
  1563.     16  : ErrorMessageString := 'Cannot remove current directory';
  1564.     17    : ErrorMessageString := 'Cannot rename across drives';
  1565.     100    : ErrorMessageString := 'Disk read error';
  1566.     101    : ErrorMessageString := 'Disk write error';
  1567.     102    : ErrorMessageString := 'File not assigned';
  1568.     103    : ErrorMessageString := 'File not open';
  1569.     104    : ErrorMessageString := 'File not open for input';
  1570.     105    : ErrorMessageString := 'File not open for output';
  1571.   end;
  1572.   case TheOpCode of
  1573.     EOC_CHANGEDIR : OperationString := 'Unable to Change Directory due to ';
  1574.     EOC_SOURCECOPY : OperationString := 'Unable to Copy due to Source File ';
  1575.     EOC_DESTCOPY : OperationString := 'Unable to Copy due to Destination File ';
  1576.     EOC_DELETEFILE : OperationString := 'Unable to Delete File due to ';
  1577.     EOC_DELETEDIR : OperationString := 'Unable to Delete Directory due to ';
  1578.     EOC_RENAMEFILE : OperationString := 'Unable to Rename File due to ';
  1579.     EOC_MAKEDIR : OperationString := 'Unable to Create New Directory due to ';
  1580.     EOC_SETATTR : OperationString := 'Unable to Set File Attributes due to ';
  1581.   end;
  1582.   { If not recognized use message; not a DOS error; reset cursor for neatness }
  1583.   if ErrorMessageString = '' then
  1584.   begin
  1585.     Screen.Cursor := crDefault;
  1586.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  1587.      TheMessage , mtError , [mbOK],0);
  1588.   end
  1589.   else
  1590.   begin
  1591.     { Recognized DOS exception, reset cursor for neatness }
  1592.     Screen.Cursor := crDefault;
  1593.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  1594.      ErrorMessageString , mtError , [mbOK], 0 );
  1595.   end;
  1596. end;
  1597.  
  1598. { This procedure handles displaying a user-friendly Dialog box with a }
  1599. { Message for DOS error codes.                                        }
  1600. procedure TFileWorkBench.HandleDOSError( TheOpCode : Integer;
  1601.            ThePath : String;  TheCode : Integer );
  1602. var ErrorMessageString : String;  { internal message holder }
  1603.     OperationString : String;     { internal message holder }
  1604. begin
  1605.   { clear the message holder to check for unrecognized code }
  1606.   ErrorMessageString := '';
  1607.   { Negate the code back to normal number and check to set string }
  1608.   case -TheCode of
  1609.     2    : ErrorMessageString := 'File not found';
  1610.     3    : ErrorMessageString := 'Path not found';
  1611.     4    : ErrorMessageString := 'Too many open files';
  1612.     5    : ErrorMessageString := 'File access denied';
  1613.     6    : ErrorMessageString := 'Invalid file handle';
  1614.     12    : ErrorMessageString := 'Invalid file access code';
  1615.     15    : ErrorMessageString := 'Invalid drive number';
  1616.     16  : ErrorMessageString := 'Cannot remove current directory';
  1617.     17    : ErrorMessageString := 'Cannot rename across drives';
  1618.     100    : ErrorMessageString := 'Disk read error';
  1619.     101    : ErrorMessageString := 'Disk write error';
  1620.     102    : ErrorMessageString := 'File not assigned';
  1621.     103    : ErrorMessageString := 'File not open';
  1622.     104    : ErrorMessageString := 'File not open for input';
  1623.     105    : ErrorMessageString := 'File not open for output';
  1624.     157 : ErrormessageString := 'Could not open Source File';
  1625.     159 : ErrormessageString := 'Could not open Target File';
  1626.   end;
  1627.   case TheOpCode of
  1628.     EOC_CHANGEDIR : OperationString := 'Unable to Change Directory due to ';
  1629.     EOC_SOURCECOPY : OperationString := 'Unable to Copy due to Source File ';
  1630.     EOC_DESTCOPY : OperationString := 'Unable to Copy due to Destination File ';
  1631.     EOC_DELETEFILE : OperationString := 'Unable to Delete File due to ';
  1632.     EOC_DELETEDIR : OperationString := 'Unable to Delete Directory due to ';
  1633.     EOC_RENAMEFILE : OperationString := 'Unable to Rename File due to ';
  1634.     EOC_MAKEDIR : OperationString := 'Unable to Create New Directory due to ';
  1635.     EOC_SETATTR : OperationString := 'Unable to Set File Attributes due to ';
  1636.   end;
  1637.   { If the string is empty an unrecognized code was sent in }
  1638.   if ErrorMessageString = '' then
  1639.   begin
  1640.     { Sent up db based on source or target error; reset cursor for neatness }
  1641.     Screen.Cursor := crDefault;
  1642.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' Error Code: ' +
  1643.      IntToStr( TheCode ) , mtError , [mbOK],0);
  1644.   end
  1645.   else  { Code is recognized, use message from case statement }
  1646.   begin
  1647.     { Format the output for source or target error }
  1648.     Screen.Cursor := crDefault;
  1649.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  1650.      ErrorMessageString , mtError , [mbOK], 0 );
  1651.   end;
  1652. end;
  1653.  
  1654. { This procedure sets the imported booleans to the file's attributes }
  1655. procedure TFileWorkBench.GetFileAttributes( TheFile : String; var IsDirectory ,
  1656.            IsArchive , IsVolumeID , IsHidden , IsReadOnly ,
  1657.             IsSysFile : Boolean );
  1658. var TheResult : Integer; { Traps for error code on VolumeID }
  1659. begin
  1660.   { Clear the imported flags for default }
  1661.   IsDirectory := false;
  1662.   IsArchive := false;
  1663.   IsVolumeID := false;
  1664.   IsHidden := False;
  1665.   IsReadOnly := false;
  1666.   IsSysFile := false;
  1667.   { Make the Dos call }
  1668.   TheResult := FileGetAttr( TheFile );
  1669.   if TheResult < 0 then
  1670.   begin
  1671.     { Volume ID returns -2 (?) }
  1672.     IsVolumeID := true;
  1673.     { It has no other properties }
  1674.     exit;
  1675.   end;
  1676.   { Use AND test to set all other properties }
  1677.   if (( TheResult and faDirectory ) = faDirectory ) then IsDirectory := true;
  1678.   if (( TheResult and faArchive ) = faArchive ) then IsArchive := true;
  1679.   if (( TheResult and faVolumeID ) = faVolumeID ) then IsVolumeID := true;
  1680.   if (( TheResult and faReadOnly ) = faReadOnly ) then IsReadOnly := true;
  1681.   if (( TheResult and faHidden ) = faHidden ) then IsHidden := true;
  1682.   if (( TheResult and faSysFile ) = faSysFile ) then IsSysFile := true;
  1683. end;
  1684.  
  1685. { This function makes sure a pathname has a trailing \ }
  1686. function TFileWorkBench.ForceTrailingBackSlash(
  1687.           const TheFileName : String ) : String;
  1688. var TempString : String;  { Used to hold function result }
  1689. begin
  1690.   { If no trailing \ add one (root will already have one.) }
  1691.   if TheFileName[ Length( TheFileName ) ] <> '\' then
  1692.    TempString := TheFileName + '\' else TempString := TheFileName;
  1693.   { Return modified or non-modified string }
  1694.   ForceTrailingBackslash := TempString;
  1695. end;
  1696.  
  1697. { This function makes sure a non-root dir has no trailing \ }
  1698. function TFileWorkBench.StripNonRootTrailingBackSlash(
  1699.           const TheFileName : String ) : String;
  1700. var TempString : String ; { Used to hold function result }
  1701. begin
  1702.   { Default is no change }
  1703.   TempString := TheFileName;
  1704.   { If not root then }
  1705.   if Length( TheFileName ) > 3 then
  1706.   begin
  1707.     { If has a trailing backslash remove it }
  1708.     if TheFileName[ Length( TheFileName )] = '\' then
  1709.     begin
  1710.       TempString := Copy( TheFileName , 1 ,
  1711.        Length( TheFileName ) - 1 );
  1712.     end;
  1713.   end;
  1714.   { Export the final result }
  1715.   StripNonRootTrailingBackSlash := TempString;
  1716. end;
  1717.  
  1718. { This gets the next selected listbox item }
  1719. function TIconFileListBox.GetNextSelection( SourceDirectory : String;
  1720.           var CurrentItem : Integer ): String;
  1721. var TheResult : String;  { Internal storage }
  1722.     finished  : boolean; { Loop flag        }
  1723. begin
  1724.   { If out of items to check signal and exit }
  1725.   if CurrentItem > Items.Count then TheResult := '' else
  1726.   begin
  1727.     { Otherwise scan from current position till match or end }
  1728.     finished := false;
  1729.     while not finished do
  1730.     begin
  1731.       { Check against selected property }
  1732.       if Selected[ CurrentItem - 1 ] then
  1733.       begin
  1734.         { If selected then return it and abort loop }
  1735.         TheResult := SourceDirectory + Items[ CurrentItem - 1 ];
  1736.         finished := true;
  1737.         { Increment current position }
  1738.         CurrentItem := CurrentItem + 1;
  1739.      end
  1740.       else
  1741.       begin
  1742.         { Increment current position }
  1743.         CurrentItem := CurrentItem + 1;
  1744.         { Otherwise check for end of data and abort if out of entries }
  1745.         if CurrentItem > Items.Count then
  1746.         begin
  1747.           TheResult := '';
  1748.           finished := true;
  1749.         end;
  1750.       end;
  1751.     end;
  1752.   end;
  1753.   { Return stored result }
  1754.   GetNextSelection := TheResult;
  1755. end;
  1756.  
  1757. { Modified from VCL Source Copyright 1995 }
  1758. { Borland International, Inc.             }
  1759. { Use this to override display with icons }
  1760. procedure TIconFileListBox.ReadFileNames;
  1761. var
  1762.   AttrIndex   : TFileAttr;
  1763.   i           : Integer;
  1764.   FileExt     : string;
  1765.   MaskPtr     : PChar;
  1766.   Ptr         : PChar;
  1767.   AttrWord    : Word;
  1768.   TempPicture : TPicture;
  1769.   TempBmp     : TBitmap;
  1770.   TempIcon    : TIcon;
  1771. const
  1772.   Attributes: array[TFileAttr] of Word =
  1773.   ( DDL_READONLY , DDL_HIDDEN , DDL_SYSTEM , $0008 , DDL_DIRECTORY ,
  1774.     DDL_ARCHIVE  , DDL_EXCLUSIVE );
  1775. begin
  1776.   { if no handle allocated yet, this call will force         }
  1777.   { one to be allocated incorrectly (i.e. at the wrong time. }
  1778.   { In due time, one will be allocated appropriately.        }
  1779.   AttrWord := DDL_READWRITE;
  1780.   if HandleAllocated then
  1781.   begin
  1782.     { Set attribute flags based on values in FileType }
  1783.     for AttrIndex := ftReadOnly to ftArchive do
  1784.      if AttrIndex in FileType then
  1785.       AttrWord := AttrWord or Attributes[ AttrIndex ];
  1786.  
  1787.     { Use Exclusive bit to exclude normal files }
  1788.     if not ( ftNormal in FileType ) then
  1789.       AttrWord := AttrWord or DDL_EXCLUSIVE;
  1790.  
  1791.     ChDir( FDirectory ); { go to the directory we want }
  1792.     Clear;               { clear the list }
  1793.  
  1794.     GetMem( MaskPtr , 256 );
  1795.     StrPCopy( MaskPtr , FMask );
  1796.     while MaskPtr <> nil do
  1797.     begin
  1798.       Ptr := StrScan ( MaskPtr , ';' );
  1799.       if Ptr <> nil then  Ptr^ := #0;
  1800.       { build the list }
  1801.       SendMessage( Handle , LB_DIR , AttrWord , Longint( MaskPtr ));
  1802.       if Ptr <> nil then
  1803.       begin
  1804.         Ptr^ := ';';
  1805.         Inc ( Ptr );
  1806.       end;
  1807.       MaskPtr := Ptr;
  1808.     end;
  1809.     FreeMem( MaskPtr , 256 );
  1810.     { Now add the bitmaps }
  1811.     {---------------------------- begin custom code --------------------------}
  1812.     { Create the TPicture for exchange purposes }
  1813.     TempPicture := TPicture.Create;
  1814.     { Set it to icon widths }
  1815.     TempPicture.Bitmap.Width := 32;
  1816.     TempPicture.Bitmap.Height := 32;
  1817.     { Run down the list }
  1818.     for i := 0 to Items.Count - 1 do
  1819.     begin
  1820.       { Create a New temporary icon }
  1821.       TempIcon := TIcon.Create;
  1822.       { Call the custom DRWS routine to get icon for a file }
  1823.       GetIconForFile( Items[ i ] , TempIcon );
  1824.       { Put the icon on the bitmap for the picture via draw }
  1825.       { Note 1 , 1 due to bug in Draw?                      }
  1826.       TempPicture.Bitmap.Canvas.Draw( 1 , 1 , TempIcon );
  1827.       { Create a temporary bitmap }
  1828.       TempBmp := TBitmap.Create;
  1829.       { Set its width to those of the previous object's bitmaps }
  1830.       TempBmp.Width := 16;
  1831.       TempBmp.Height := 15;
  1832.       { Resize the icon's bitmap to the smaller size with stretchdraw }
  1833.       TempBmp.Canvas.StretchDraw( Rect( 1 , 1 , 15 , 14 ) ,
  1834.        TempPicture.Bitmap );
  1835.       { Set the Objects list to the bitmap }
  1836.       Items.Objects[ i ] := TempBmp;
  1837.       { Free the icon each iteration; don't free the TempBmp as list does }
  1838.       TempIcon.Free;
  1839.     end;
  1840.     { Free the TPicture exchange element }
  1841.     TempPicture.Free;
  1842.     {------------------------ end custom code --------------------------------}
  1843.     Change;
  1844.   end;
  1845. end;
  1846.  
  1847. { Use this to respond to dbl-clicking FLB filename }
  1848. procedure TIconFileListBox.TheDblClick(Sender: TObject);
  1849. begin
  1850.   { Call shellexec as a wrapper around ShellExecute API call }
  1851.   { False indicates failure, signal error                    }
  1852.   if not ShellExec( ExpandFileName( Items[ ItemIndex ] ), '' , '', false ,
  1853.    SW_SHOWNORMAL , false ) then MessageDlg('Could not Shell out to ' +
  1854.     Items[ ItemIndex ] , mtError, [mbOK], 0);
  1855. end;
  1856.  
  1857. { Create method for FIP                                }
  1858. constructor TIconFileListBox.Create( AOwner : TComponent );
  1859. begin
  1860.   { call inherited -- VITAL! }
  1861.   inherited Create( AOwner );
  1862.   { set the mouse method }
  1863.   OnDblClick := TheDblClick;
  1864. end;
  1865.  
  1866. { Create method for FIP                                }
  1867. constructor TFileIconPanel.Create( AOwner : TComponent );
  1868. begin
  1869.   { call inherited -- VITAL! }
  1870.   inherited Create( AOwner );
  1871.   { create icon and label components, making self owner/displayer }
  1872.   FTheIcon := TIcon.Create;
  1873.   FTheLabel := TLabel.Create( Self );
  1874.   FThelabel.Parent := Self;
  1875.   { Set own and labels mouse methods to stored methods }
  1876.   OnMouseUp := TheMouseUp;
  1877.   OnMouseDown := TheMouseDown;
  1878.   OnMouseMove := TheMouseMove;
  1879.   OnDragOver := TheDragOver;
  1880.   OnDragDrop := TheDragDrop;
  1881.   { Set alignment and autosize properties of the label }
  1882.   FTheLabel.Autosize := false;
  1883.   FTheLabel.Alignment := taCenter;
  1884.   { Set selected to false }
  1885.   Selected := false;
  1886. end;
  1887.  
  1888. procedure TFileIconPanel.WMLButtonDblClk(var Message: TWMLButtonDblClk);
  1889. var CurrentDirectory : String;    { Use to store dirs }
  1890.     TheDrive         : String;    { Get drive letter  }
  1891.     WhichDrive       : Integer;   { Get drive number  }
  1892.     ErrorCheck       : Integer;
  1893.     TheFWB           : TFileWorkBench;
  1894. begin
  1895.   { Create FileWorkBench for later use }
  1896.   TheFWB := TFileWorkBench.Create( Self );
  1897.   { Check for label or FIP sender }
  1898.   if FTheLabel.Caption = '..' then
  1899.   begin { deal with backup request }
  1900.     { Change to New directory }
  1901.     TheFWB.ChangeTheDirectory( '..' );
  1902.     { Call special method due to SendMessage problem! }
  1903.     TFileIconPanelScrollBox( Parent ).Update;
  1904.   end
  1905.   else
  1906.   begin
  1907.     { Check for DRIVE id in name }
  1908.     if Pos( 'DRIVE' , FTheName ) <> 0 then
  1909.     begin { Double Click on a Drive Icon }
  1910.       { Pull out the letter from name }
  1911.       TheDrive := Copy( FtheName , 7 , 1 );
  1912.       { Convert it to a number }
  1913.       WhichDrive := ( Ord( TheDrive[ 1 ] ) - Ord( 'A' )) + 1;
  1914.       TheFWB.ChangeTheDriveAndDirectory( WhichDrive );
  1915.       { Call special method due to SendMessage problem! }
  1916.       TFileIconPanelScrollBox( Parent ).Update;
  1917.     end
  1918.     else
  1919.     begin { Double click on a dir/file icon }
  1920.       if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  1921.       begin { A directory, change to it }
  1922.         { Since full path in name, simply change to it! }
  1923.         TheFWB.ChangeTheDirectory( FTheName );
  1924.         { Call special method due to SendMessage problem! }
  1925.         TFileIconPanelScrollBox( Parent ).Update;
  1926.       end
  1927.       else
  1928.       begin { A file; attempt to shellexecute it }
  1929.         { Call shellexec as a wrapper around ShellExecute API call }
  1930.         { False indicates failure, signal error                    }
  1931.         if not ShellExec( FTheName , '' , '', false , SW_SHOWNORMAL , false )
  1932.          then MessageDlg('Could not Shell out to ' + FTheName , mtError,
  1933.           [mbOK], 0);
  1934.       end;
  1935.     end;
  1936.   end;
  1937.   TheFWB.Free; { This prevents resource leak }
  1938. end;
  1939.  
  1940. { Initialization method for FIP                                         }
  1941. procedure TFileIconPanel.Initialize( PanelX              ,
  1942.                                      PanelY              ,
  1943.                                      PanelWidth          ,
  1944.                                      PanelHeight         ,
  1945.                                      PanelBevelWidth     ,
  1946.                                      LabelFontSize         : Integer;
  1947.                                      PanelColor          ,
  1948.                                      PanelHighlightColor ,
  1949.                                      PanelShadowColor    ,
  1950.                                      LabelTextColor        : TColor;
  1951.                                      TheFilename         ,
  1952.                                      LabelFontName         : String;
  1953.                                      LabelFontStyle        : TFontStyles;
  1954.                                      ExtraData             : Integer );
  1955.  
  1956. var TheLabelHeight ,             { Holder for label pixel height }
  1957.     TheLabelWidth    : Integer;  { Holder for label pixel width  }
  1958.     TheOtherPChar    : PChar;    { Windows ASCIIZ string         }
  1959.     HolderBMP        : TBitmap;  { Holds working bitmap for tnail}
  1960.     HoldName         : String;
  1961. begin
  1962.   { Set the basic properties based on imported parameters }
  1963.   Left := PanelX;
  1964.   Top := PanelY;
  1965.   Width := PanelWidth;
  1966.   Height := PanelHeight;
  1967.   Color := PanelColor;
  1968.   BevelWidth := PanelBevelWidth;
  1969.   FHighlightColor := PanelHighlightColor;
  1970.   FShadowColor := PanelShadowColor;
  1971.   FTheName := TheFilename;
  1972.   { If the ExtraData field is non-0 then a drive is being sent in }
  1973.   if ExtraData <> 0 then
  1974.   begin
  1975.     { Use the data field value to determine which icon to get from RES file }
  1976.     case ExtraData of
  1977.       1 : begin
  1978.             GetMem( TheOtherPChar , 255 );
  1979.             StrPCopy( TheOtherPChar , 'FLOPPY35' );
  1980.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1981.             FreeMem( TheOtherPChar , 255 );
  1982.           end;
  1983.       2 : begin
  1984.             GetMem( TheOtherPChar , 255 );
  1985.             StrPCopy( TheOtherPChar , 'FIXEDHD' );
  1986.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1987.             FreeMem( TheOtherPChar , 255 );
  1988.           end;
  1989.       3 : begin
  1990.             GetMem( TheOtherPChar , 255 );
  1991.             StrPCopy( TheOtherPChar , 'NETWORKHD' );
  1992.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1993.             FreeMem( TheOtherPChar , 255 );
  1994.           end;
  1995.       4 : begin
  1996.             GetMem( TheOtherPChar , 255 );
  1997.             StrPCopy( TheOtherPChar , 'CDROM' );
  1998.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1999.             FreeMem( TheOtherPChar , 255 );
  2000.           end;
  2001.       5 : begin
  2002.             GetMem( TheOtherPChar , 255 );
  2003.             StrPCopy( TheOtherPChar , 'RAM' );
  2004.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  2005.             FreeMem( TheOtherPChar , 255 );
  2006.           end;
  2007.     end;
  2008.     { The FileNme property is already set up for the caption; use directly }
  2009.     FTheLabel.Caption := TheFilename;
  2010.     { Set up the hint for later use (make sure to set ShowHint) }
  2011.     Hint := 'Change to ' + TheFileName;
  2012.     ShowHint := true;
  2013.     { Set up all imported label properties and center it for drawing }
  2014.     with FTheLabel do
  2015.     begin
  2016.       Font.Name := LabelFontName;
  2017.       Font.Size := LabelFontSize;
  2018.       Font.Style := LabelFontStyle;
  2019.       Font.Color := LabelTextColor;
  2020.       Canvas.Brush.Color := PanelColor;
  2021.       Canvas.Font := Font;
  2022.       TheLabelHeight := Canvas.Textheight( Caption ) + 4;
  2023.       TheLabelWidth := Canvas.Textwidth( Caption ) + 4;
  2024.       Left := (( Self.Width - TheLabelWidth ) div 2 ) + 1;
  2025.       Top := ((( Round( Self.Height * 0.25 ) - 6 ) - TheLabelHeight) div 2) + 1;
  2026.       Top := Top + Round( Self.Height * 0.75 );
  2027.       Height := TheLabelHeight;
  2028.       Width := TheLabelWidth;
  2029.     end;
  2030.   end
  2031.   else
  2032.   begin
  2033.     { A file or directory has been sent in; use GetIconForFile to obtain an }
  2034.     { icon either from the file, its owner, or a RES file default.          }
  2035.     GetIconForFile( FTheName , FTheIcon );
  2036.     { Check for the Backup caption and set it specially }
  2037.     if ExtractfileName( FThename ) = '..' then
  2038.     begin
  2039.       FTheLabel.Caption := '..';
  2040.       Hint := 'Up One Level';
  2041.     end
  2042.     else
  2043.     begin
  2044.       if Uppercase( ExtractFileExt( FTheName )) = '.BMP' then
  2045.       begin
  2046.         HolderBMP := TBitmap.Create;
  2047.         HolderBMP.LoadFromFile( FTheName );
  2048.         FTheBMP := CreateBitmapThumbNailFromBitmap( HolderBMP , ThumbNailWidth ,
  2049.          ThumbNailHeight );
  2050.         HolderBMP.Free;
  2051.         HoldName := ExtractFileName( FTheName );
  2052.         HoldName := Copy( HoldName, 1 , Length( HoldName ) - 4 );
  2053.         HoldName := HoldName + '.THU';
  2054.         FTheBMP.SaveToFile( ExpandFileName( HoldName ));
  2055.         FTheLabel.caption := ExtractFileName( UpperCase( FTheName ));
  2056.         Hint := FTheName;
  2057.       end
  2058.       else
  2059.       begin
  2060.         { Otherwise just get the filename for the label caption }
  2061.         { And the full path for the hint (used later.)          }
  2062.         FTheLabel.caption := ExtractFileName( UpperCase( FTheName ));
  2063.         Hint := FTheName;
  2064.       end;
  2065.     end;
  2066.     { Activate showhint so hints are seen }
  2067.     ShowHint := true;
  2068.     { Set label properties with imported values and center for display }
  2069.     with FTheLabel do
  2070.     begin
  2071.       Font.Name := LabelFontName;
  2072.       Font.Size := LabelFontSize;
  2073.       Font.Style := LabelFontStyle;
  2074.       Font.Color := LabelTextColor;
  2075.       Canvas.Brush.Color := PanelColor;
  2076.       Canvas.Font := Font;
  2077.       TheLabelHeight := Canvas.Textheight( Caption ) + 4;
  2078.       TheLabelWidth := Canvas.Textwidth( Caption ) + 4;
  2079.       Left := (( Self.Width - TheLabelWidth ) div 2 ) + 1;
  2080.       Top := ((( Round( Self.Height * 0.25 ) - 6 ) - TheLabelHeight) div 2) + 1;
  2081.       Top := Top + Round( Self.Height * 0.75 );
  2082.       Height := TheLabelHeight;
  2083.       Width := TheLabelWidth;
  2084.     end;
  2085.   end;
  2086. end;
  2087.  
  2088. { Destroy method for FIP }
  2089. destructor TFileIconPanel.Destroy;
  2090. begin
  2091.   { free component resources }
  2092.   if assigned( FTheIcon ) then FTheIcon.Free;
  2093.   FTheLabel.Free;
  2094.   if Assigned( FTheBMP ) then FTheBMP.Free;
  2095.   { call inherited -- VITAL! }
  2096.   inherited Destroy;
  2097. end;
  2098.  
  2099. { Mousedown method for FIP; used to allow dragging }
  2100. procedure TFileIconPanel.TheMouseDown(Sender: TObject;
  2101.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  2102. var ThePoint , TheOtherPoint : TPoint;
  2103. begin
  2104.   { Begin a conditional drag operation (false allows timer) }
  2105.   TheIOManager.WhichButton := Button;
  2106.   TheIOManager.WhichState := Shift;
  2107.   { Currently ignore drive clicks }
  2108.   if Pos( 'DRIVE' , FTheName ) > 0 then exit;
  2109.   if (( Button = mbRight ) and ( ssShift in Shift )) then
  2110.   begin
  2111.     TheTempBitmap := TBitmap.Create;
  2112.     TheTempBitmap.Width := Self.Width;
  2113.     TheTempBitmap.Height := Self.Height;
  2114.     TheTempBitmap.Canvas.Copyrect( Rect( 0 , 0 , Self.Width , Self.Height ) ,
  2115.      Self.Canvas , Rect( 0 , 0 , Self.Width , Self.Height ));
  2116.     TheMouseManager.InitializeBitmap( TheTempBitmap );
  2117.     ThePoint.X := X;
  2118.     ThePoint.Y := Y;
  2119.     TheOtherPoint := ClientToScreen( ThePoint );
  2120.     TheMouseManager.StartBitmapCursor( TheOtherPoint.X , TheOtherPoint.Y );
  2121.     BitmapDragging := true;
  2122.     GlobalSource := Self;
  2123.     exit;
  2124.   end;
  2125.   if Button = mbRight then
  2126.   begin
  2127.     TheMouseManager.InitializeIcon( FTheIcon );
  2128.     ThePoint.X := X;
  2129.     ThePoint.Y := Y;
  2130.     TheOtherPoint := ClientToScreen( ThePoint );
  2131.     TheMouseManager.StartIconCursor( TheOtherPoint.X , TheOtherPoint.Y );
  2132.     IconDragging := true;
  2133.     GlobalSource := Self;
  2134.     exit;
  2135.   end;
  2136.   if button <> mbRight then BeginDrag( false );
  2137.   { Flip status of bevels }
  2138.   if BevelOuter = bvRaised then BevelOuter := bvLowered else
  2139.    BevelOuter := bvRaised;
  2140.   { Flip selected variable }
  2141.   Selected := not Selected;
  2142.   { Set redisplay }
  2143. end;
  2144.  
  2145. procedure TFileIconPanel.TheMouseMove(Sender: TObject; Shift: TShiftState;
  2146.   X, Y: Integer);
  2147. var ThePoint, TheOtherPoint : TPoint;
  2148. begin
  2149.   if IconDragging then
  2150.   begin
  2151.     ThePoint.X := X;
  2152.     ThePoint.Y := Y;
  2153.     TheOtherPoint := ClientToScreen( ThePoint );
  2154.     TheMouseManager.MoveIconCursor( TheOtherPoint.X , TheOtherPoint.Y );
  2155.     exit;
  2156.   end;
  2157.   if BitmapDragging then
  2158.   begin
  2159.     ThePoint.X := X;
  2160.     ThePoint.Y := Y;
  2161.     TheOtherPoint := ClientToScreen( ThePoint );
  2162.     TheMouseManager.MoveBitmapCursor( TheOtherPoint.X , TheOtherPoint.Y );
  2163.     exit;
  2164.   end;
  2165. end;
  2166.  
  2167. { Mouseup Method for FIP; used to allow dragging }
  2168. procedure TFileIconPanel.TheMouseUp(Sender: TObject;
  2169.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  2170. begin
  2171.   if IconDragging then
  2172.   begin
  2173.     TheMouseManager.EndIconCursor( X , Y );
  2174.     IconDragging := false;
  2175.     if GlobalSource <> Self then
  2176.     begin { Right-drag onto a panel! }
  2177.       TheDragDrop( Sender , GlobalSource , X , Y );
  2178.     end;
  2179.     exit;
  2180.   end;
  2181.   if BitmapDragging then
  2182.   begin
  2183.     TheMouseManager.EndBitmapCursor( X , Y );
  2184.     BitmapDragging := false;
  2185.     if GlobalSource <> Self then
  2186.     begin { Right-drag onto a panel! }
  2187.       TheDragDrop( Sender , GlobalSource , X , Y );
  2188.     end;
  2189.     exit;
  2190.   end;
  2191.   { End a drag operation without dropping; if dragged OK }
  2192.   { already handled.                                     }
  2193.   {EndDrag( false );}
  2194.   { If the right button is clicked, perform magic! }
  2195.   { Redisplay on general principles }
  2196.   Invalidate;
  2197. end;
  2198.  
  2199. { Use this to generically OK DnD from FIPs }
  2200. procedure TFileIconPanel.TheDragOver(Sender, Source: TObject; X,
  2201.   Y: Integer; State: TDragState; var Accept: Boolean);
  2202. begin
  2203.   { Only accept from FileIconPanel components }
  2204.   if Source is TFileIconPanel then Accept := true else Accept := false;
  2205. end;
  2206.  
  2207. { Use this to accept Drag and Drop from other FIPs }
  2208. procedure TFileIconPanel.TheDragDrop(Sender, Source: TObject; X,
  2209.   Y: Integer);
  2210. var CurrentName ,                 { Holds work name}
  2211.     TheOldString : String;        { Holds Dir      }
  2212.     TargetDir    : String;        { target of op   }
  2213.     TheResult       : Integer;    { Modal res hold }
  2214.     SourceDirectory,
  2215.     TargetDirectory,
  2216.     CurrentDirectory : String;    { Use to store dirs }
  2217.     TheDrive         : String;    { Get drive letter  }
  2218.     WhichDrive       : Integer;   { Get drive number  }
  2219.     ErrorCheck       : Integer;
  2220.     TheFWB           : TFileWorkBench;
  2221.     ThePosition : Integer;
  2222.     Finished : Boolean;
  2223.     TheFIPSB : TFileIconPanelScrollBox;
  2224. begin
  2225.   { If drop target is .. then ignore }
  2226.   if FTheLabel.Caption = '..' then exit;
  2227.   { Likewise ignore Dnd from drive icons }
  2228.   if Pos( 'DRIVE' , TFileIconPanel( Source ).FtheName ) > 0 then exit;
  2229.   { Obtain the parent of the source FIP; may not be self }
  2230.   TheFIPSB := TFileIconPanelScrollBox( TFileIconPanel( Source ).Parent );
  2231.   { Obtain source directory either as Dir or filepath }
  2232.   if (( FileGetAttr( TFileIconPanel( Source ).FTheName )
  2233.    and faDirectory ) = faDirectory ) then
  2234.   begin  { Directory; take whole path }
  2235.     SourceDirectory := TFileIconPanel( Source ).FTheName;
  2236.   end
  2237.   else
  2238.   begin { File; get pathname }
  2239.     SourceDirectory := ExtractFilePath( TFileIconPanel( Source ).FTheName );
  2240.   end;
  2241.   Sourcedirectory := TheFIPSB.TheFWB.ForceTrailingBackSlash( SourceDirectory );
  2242.   if Pos( 'DRIVE' , FTheName ) > 0 then
  2243.   begin { Drop onto a drive icon; perform action to its default dir }
  2244.     { Pull out the letter from name }
  2245.     TheDrive := Copy( FtheName , 7 , 1 );
  2246.     { Convert it to a number }
  2247.     WhichDrive := ( Ord( TheDrive[ 1 ] ) - Ord( 'A' )) + 1;
  2248.     { Determine the target directory and drive }
  2249.     GetDir( WhichDrive , TargetDirectory );
  2250.     TargetDirectory := TheFIPSB.TheFWB.ForceTrailingbackSlash( TargetDirectory );
  2251.     { Check for shift to operate on all selections }
  2252.     if TheIOManager.WasSHIFTPressed then
  2253.     begin { Operate on all selections }
  2254.       { Obtain the parent directory of the FIP dragged over }
  2255.       SourceDirectory := ExtractFilePath( TFileIconPanel( Source ).FTheName );
  2256.       SourceDirectory := TheFIPSB.TheFWB.ForceTrailingBackslash( SourceDirectory );
  2257.       { If SourceDir subset of TargetDir then abort; recursive failure }
  2258.       if Pos( SourceDirectory , TargetDirectory ) > 0 then
  2259.       begin
  2260.         MessageDlg( 'Cannot drag to same directory!',mtError,[mbOK],0 );
  2261.         exit;
  2262.       end;
  2263.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  2264.       begin { Copy to different drives }
  2265.         if TheIOManager.WasALTPressed then
  2266.         begin { ALT overrides and does move }
  2267.           { Set up to get all current selections }
  2268.           ThePosition := 1;
  2269.           finished := false;
  2270.           while not finished do
  2271.           begin
  2272.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2273.                    ThePosition );
  2274.             { If returns blank string then out of selections }
  2275.             if CurrentName = '' then finished := true else
  2276.             begin
  2277.               { If a directory signal error }
  2278.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2279.               begin
  2280.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  2281.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2282.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  2283.                    TargetDirectory );
  2284.               end
  2285.               else
  2286.               begin
  2287.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  2288.               end;
  2289.             end;
  2290.             { Reset to normal cursor }
  2291.             Screen.Cursor := crDefault;
  2292.           end;
  2293.         end
  2294.         else
  2295.         begin { Default is to do copy like file manager }
  2296.           { Set up to get all current selections }
  2297.           ThePosition := 1;
  2298.           finished := false;
  2299.           while not finished do
  2300.           begin
  2301.              CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2302.                    ThePosition );
  2303.             { If returns blank string then out of selections }
  2304.             if CurrentName = '' then finished := true else
  2305.             begin
  2306.               { If a directory signal error }
  2307.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2308.               begin
  2309.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  2310.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2311.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  2312.                    TargetDirectory );
  2313.               end
  2314.               else
  2315.               begin
  2316.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  2317.               end;
  2318.             end;
  2319.             { Reset to normal cursor }
  2320.             Screen.Cursor := crDefault;
  2321.           end;
  2322.         end;
  2323.       end
  2324.       else
  2325.       begin { Copy to same drive }
  2326.         if TheIOManager.WasCTRLPressed then
  2327.         begin { CTRL overrides and does copy }
  2328.           { Set up to get all current selections }
  2329.           ThePosition := 1;
  2330.           finished := false;
  2331.           while not finished do
  2332.           begin
  2333.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2334.                    ThePosition );
  2335.             { If returns blank string then out of selections }
  2336.             if CurrentName = '' then finished := true else
  2337.             begin
  2338.               { If a directory signal error }
  2339.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2340.               begin
  2341.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  2342.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2343.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  2344.                    TargetDirectory );
  2345.               end
  2346.               else
  2347.               begin
  2348.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  2349.               end;
  2350.             end;
  2351.             { Reset to normal cursor }
  2352.             Screen.Cursor := crDefault;
  2353.           end;
  2354.         end
  2355.         else
  2356.         begin { Default is to do move like file manager }
  2357.           { Set up to get all current selections }
  2358.           ThePosition := 1;
  2359.           finished := false;
  2360.           while not finished do
  2361.           begin
  2362.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2363.                    ThePosition );
  2364.             { If returns blank string then out of selections }
  2365.             if CurrentName = '' then finished := true else
  2366.             begin
  2367.               { If a directory signal error }
  2368.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2369.               begin
  2370.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  2371.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2372.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  2373.                    TargetDirectory );
  2374.               end
  2375.               else
  2376.               begin
  2377.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  2378.               end;
  2379.             end;
  2380.             { Reset to normal cursor }
  2381.             Screen.Cursor := crDefault;
  2382.           end;
  2383.         end;
  2384.       end;
  2385.     end
  2386.     else
  2387.     begin { Operate on only source }
  2388.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  2389.       begin { Copy to different drives }
  2390.         if TheIOManager.WasALTPressed then
  2391.         begin { ALT overrides and does move }
  2392.           with Source as TFileIconPanel do
  2393.           begin
  2394.             if MessageDlg( 'Move ' + FTheName + ' to ' +
  2395.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2396.               TheFIPSB.TheFWB.MoveTheFile( FTheName , TargetDirectory );
  2397.           end;
  2398.         end
  2399.         else
  2400.         begin { Default is to do copy like file manager }
  2401.           with Source as TFileIconPanel do
  2402.           begin
  2403.             if MessageDlg( 'Copy ' + FTheName + ' to ' +
  2404.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2405.               TheFIPSB.TheFWB.CopyTheFile( FtheName , TargetDirectory );
  2406.           end;
  2407.         end;
  2408.       end
  2409.       else
  2410.       begin { Copy to same drive }
  2411.         if TheIOManager.WasCTRLPressed then
  2412.         begin { CTRL overrides and does copy }
  2413.           with Source as TFileIconPanel do
  2414.           begin
  2415.             if MessageDlg( 'Copy ' + FTheName + ' to ' +
  2416.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2417.               TheFIPSB.TheFWB.CopyTheFile( FTheName , TargetDirectory );
  2418.           end;
  2419.         end
  2420.         else
  2421.         begin { Default is to do move like file manager }
  2422.           with Source as TFileIconPanel do
  2423.           begin
  2424.             if MessageDlg( 'Move ' + FTheName + ' to ' +
  2425.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2426.              TheFIPSB.TheFWB.MoveTheFile( FtheName , TargetDirectory );
  2427.           end;
  2428.         end;
  2429.       end;
  2430.     end;
  2431.   end
  2432.   else
  2433.   begin { Drop onto dir or file icon }
  2434.     if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  2435.     begin { Drop onto a directory; use its path as target }
  2436.       TargetDirectory := FTheName;
  2437.     end
  2438.     else
  2439.     begin { Drop onto a file; use its parent as target }
  2440.       TargetDirectory := ExtractFilePath( FTheName );
  2441.     end;
  2442.     Targetdirectory := TheFIPSB.TheFWB.ForceTrailingbackslash( TargetDirectory );
  2443.     { Check for shift to operate on all selections }
  2444.     if TheIOManager.WasSHIFTPressed then
  2445.     begin { Operate on all selections }
  2446.       { Obtain the parent directory of the FIP dragged over }
  2447.       SourceDirectory := ExtractFilePath( TFileIconPanel( Source ).FTheName );
  2448.       SourceDirectory := TheFIPSB.TheFWB.ForceTrailingBackslash( SourceDirectory );
  2449.       { If SourceDir subset of TargetDir then abort; recursive failure }
  2450.       if Pos( SourceDirectory , TargetDirectory ) > 0 then
  2451.       begin
  2452.         MessageDlg( 'Cannot drag to same directory!',mtError,[mbOK],0 );
  2453.         exit;
  2454.       end;
  2455.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  2456.       begin { Copy to different drives }
  2457.         if TheIOManager.WasALTPressed then
  2458.         begin { ALT overrides and does move }
  2459.           { Set up to get all current selections }
  2460.           ThePosition := 1;
  2461.           finished := false;
  2462.           while not finished do
  2463.           begin
  2464.              CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2465.                    ThePosition );
  2466.             { If returns blank string then out of selections }
  2467.             if CurrentName = '' then finished := true else
  2468.             begin
  2469.               { If a directory signal error }
  2470.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2471.               begin
  2472.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  2473.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2474.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  2475.                    TargetDirectory );
  2476.               end
  2477.               else
  2478.               begin
  2479.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  2480.               end;
  2481.             end;
  2482.             { Reset to normal cursor }
  2483.             Screen.Cursor := crDefault;
  2484.           end;
  2485.         end
  2486.         else
  2487.         begin { Default is to do copy like file manager }
  2488.           { Set up to get all current selections }
  2489.           ThePosition := 1;
  2490.           finished := false;
  2491.           while not finished do
  2492.           begin
  2493.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2494.                    ThePosition );
  2495.             { If returns blank string then out of selections }
  2496.             if CurrentName = '' then finished := true else
  2497.             begin
  2498.               { If a directory signal error }
  2499.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2500.               begin
  2501.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  2502.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2503.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  2504.                    TargetDirectory );
  2505.               end
  2506.               else
  2507.               begin
  2508.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  2509.               end;
  2510.             end;
  2511.             { Reset to normal cursor }
  2512.             Screen.Cursor := crDefault;
  2513.           end;
  2514.         end;
  2515.       end
  2516.       else
  2517.       begin { Copy to same drive }
  2518.         if TheIOManager.WasCTRLPressed then
  2519.         begin { CTRL overrides and does copy }
  2520.           { Set up to get all current selections }
  2521.           ThePosition := 1;
  2522.           finished := false;
  2523.           while not finished do
  2524.           begin
  2525.             { Call generic file getting routine based on current view}
  2526.              CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2527.                    ThePosition );
  2528.             { If returns blank string then out of selections }
  2529.             if CurrentName = '' then finished := true else
  2530.             begin
  2531.               { If a directory signal error }
  2532.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2533.               begin
  2534.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  2535.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2536.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  2537.                    TargetDirectory );
  2538.               end
  2539.               else
  2540.               begin
  2541.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  2542.               end;
  2543.             end;
  2544.             { Reset to normal cursor }
  2545.             Screen.Cursor := crDefault;
  2546.           end;
  2547.         end
  2548.         else
  2549.         begin { Default is to do move like file manager }
  2550.           { Set up to get all current selections }
  2551.           ThePosition := 1;
  2552.           finished := false;
  2553.           while not finished do
  2554.           begin
  2555.             { Call generic file getting routine based on current view}
  2556.               CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2557.                    ThePosition );
  2558.             { If returns blank string then out of selections }
  2559.             if CurrentName = '' then finished := true else
  2560.             begin
  2561.               { If a directory signal error }
  2562.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2563.               begin
  2564.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  2565.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2566.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  2567.                    TargetDirectory );
  2568.               end
  2569.               else
  2570.               begin
  2571.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  2572.               end;
  2573.             end;
  2574.             { Reset to normal cursor }
  2575.             Screen.Cursor := crDefault;
  2576.           end;
  2577.         end;
  2578.       end;
  2579.     end
  2580.     else
  2581.     begin { Operate on only source }
  2582.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  2583.       begin { Copy to different drives }
  2584.         if TheIOManager.WasALTPressed then
  2585.         begin { ALT overrides and does move }
  2586.           with Source as TFileIconPanel do
  2587.           begin
  2588.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  2589.             begin
  2590.               if MessageDlg( 'Move Directory ' + FTheName + ' to ' +
  2591.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2592.                 TheFIPSB.TheFWB.RecursivelyMoveDirectory( FtheName ,
  2593.                  TargetDirectory );
  2594.             end
  2595.             else
  2596.             begin
  2597.               if MessageDlg( 'Move ' + FTheName + ' to ' +
  2598.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2599.                 TheFIPSB.TheFWB.MoveTheFile( FTheName , TargetDirectory );
  2600.             end;
  2601.           end;
  2602.         end
  2603.         else
  2604.         begin { Default is to do copy like file manager }
  2605.           with Source as TFileIconPanel do
  2606.           begin
  2607.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  2608.             begin
  2609.               if MessageDlg( 'Copy Directory ' + FtheName + ' to ' +
  2610.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2611.                 TheFIPSB.TheFWB.RecursivelyCopyDirectory( FtheName ,
  2612.                  TargetDirectory );
  2613.             end
  2614.             else
  2615.             begin
  2616.               if MessageDlg( 'Copy ' + FTheName + ' to ' +
  2617.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2618.                 TheFIPSB.TheFWB.CopyTheFile( FTheName , TargetDirectory );
  2619.             end;
  2620.           end;
  2621.         end;
  2622.       end
  2623.       else
  2624.       begin { Copy to same drive }
  2625.         if TheIOManager.WasCTRLPressed then
  2626.         begin { CTRL overrides and does copy }
  2627.           with Source as TFileIconPanel do
  2628.           begin
  2629.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  2630.             begin
  2631.               if MessageDlg( 'Copy Directory ' + FtheName + ' to ' +
  2632.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2633.                 TheFIPSB.TheFWB.RecursivelyCopyDirectory( FtheName ,
  2634.                  TargetDirectory );
  2635.             end
  2636.             else
  2637.             begin
  2638.               if MessageDlg( 'Copy ' + FTheName + ' to ' +
  2639.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2640.                 TheFIPSB.TheFWB.CopyTheFile( FTheName , TargetDirectory );
  2641.             end;
  2642.           end;
  2643.         end
  2644.         else
  2645.         begin { Default is to do move like file manager }
  2646.           with Source as TFileIconPanel do
  2647.           begin
  2648.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  2649.             begin
  2650.               if MessageDlg( 'Move Directory ' + FtheName + ' to ' +
  2651.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2652.                 TheFIPSB.TheFWB.RecursivelyMoveDirectory( FtheName ,
  2653.                  TargetDirectory );
  2654.             end
  2655.             else
  2656.             begin
  2657.               if MessageDlg( 'Move ' + FTheName + ' to ' +
  2658.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2659.                 TheFIPSB.TheFWB.MoveTheFile( FTheName , TargetDirectory );
  2660.             end;
  2661.           end;
  2662.         end;
  2663.       end;
  2664.     end;
  2665.   end;
  2666.   { Call special method due to SendMessage problem! }
  2667.   TFileIconPanelScrollBox( TFileIconPanel( Source ).Parent ).Update;
  2668.   TFileIconPanelScrollBox( Parent ).Update;
  2669. end;
  2670.  
  2671. { Paint method for FIP; overrides normal paint }
  2672. procedure TFileIconPanel.Paint;
  2673. var
  2674.   TheOtherRect   : TRect;   { Holds clientrect   }
  2675.   TopColor     ,            { Holds bright color }
  2676.   BottomColor    : TColor;  { Holds dark color   }
  2677.  
  2678. { These methods are from Borland Intl., copyright 1995 }
  2679. procedure Frame3D(    Canvas       : TCanvas;
  2680.                   var TheRect      : TRect;
  2681.                       TopColor   ,
  2682.                       BottomColor  : TColor;
  2683.                       Width        : Integer );
  2684.  
  2685. procedure DoRect;
  2686. var
  2687.   TopRight, BottomLeft: TPoint;
  2688. begin
  2689.   with Canvas, TheRect do
  2690.   begin
  2691.     TopRight.X := Right;
  2692.     TopRight.Y := Top;
  2693.     BottomLeft.X := Left;
  2694.     BottomLeft.Y := Bottom;
  2695.     Pen.Color := TopColor;
  2696.     PolyLine([BottomLeft, TopLeft, TopRight]);
  2697.     Pen.Color := BottomColor;
  2698.     Dec(BottomLeft.X);
  2699.     PolyLine([TopRight, BottomRight, BottomLeft]);
  2700.   end;
  2701. end;
  2702.  
  2703. begin
  2704.   Canvas.Pen.Width := 1;
  2705.   Dec(TheRect.Bottom); Dec(TheRect.Right);
  2706.   while Width > 0 do
  2707.   begin
  2708.     Dec(Width);
  2709.     DoRect;
  2710.     InflateRect(TheRect, -1, -1);
  2711.   end;
  2712.   Inc(TheRect.Bottom); Inc(TheRect.Right);
  2713. end;
  2714.  
  2715. procedure AdjustColors(Bevel: TPanelBevel);
  2716. begin
  2717.   TopColor := FHighlightColor;
  2718.   if Bevel = bvLowered then TopColor := FShadowColor;
  2719.   BottomColor := FShadowColor;
  2720.   if Bevel = bvLowered then BottomColor := FHighlightColor;
  2721. end;
  2722.  
  2723. { Custom code begins here }
  2724. begin
  2725.   { Get the rectangle of the control with API/method call }
  2726.   TheOtherRect := GetClientRect;
  2727.   { draw basic rectangle with basic color }
  2728.   with Canvas do
  2729.   begin
  2730.     Brush.Color := Color;
  2731.     FillRect(TheOtherRect);
  2732.   end;
  2733.   { Set up for top "icon" frame  and draw it with frame3d }
  2734.   TheOtherRect.Right := Width;
  2735.   TheOtherRect.Bottom := Round( Height * 0.75 ) - 6 ;
  2736.   if BevelOuter <> bvNone then
  2737.   begin
  2738.     AdjustColors(BevelOuter);
  2739.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  2740.   end;
  2741.   Frame3D(Canvas, TheOtherRect, Color, Color, BorderWidth);
  2742.   if BevelInner <> bvNone then
  2743.   begin
  2744.     AdjustColors(BevelInner);
  2745.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  2746.   end;
  2747.   { Do the same for the lower "label" frame }
  2748.   TheOtherRect.Top := Round( Height * 0.75 ) - 5;
  2749.   TheOtherRect.Left := 0;
  2750.   TheOtherRect.Bottom := Height;
  2751.   TheOtherRect.Right := Width;
  2752.   if BevelOuter <> bvNone then
  2753.   begin
  2754.     AdjustColors(BevelOuter);
  2755.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  2756.   end;
  2757.   Frame3D(Canvas, TheOtherRect, Color, Color, BorderWidth);
  2758.   if BevelInner <> bvNone then
  2759.   begin
  2760.     AdjustColors(BevelInner);
  2761.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  2762.   end;
  2763.   if Assigned( FTheBMP ) then
  2764.   begin
  2765.     Canvas.Draw( (( Width - ThumbNailWidth ) div 2 ) ,
  2766.     ((( Round( Height * 0.75 ) - 6 ) - ThumbNailHeight ) div 2 ) , FTheBMP );
  2767.   end
  2768.   else
  2769.   begin
  2770.     { Then draw the icon using canvas draw method }
  2771.     Canvas.Draw( (( Width - 32 ) div 2 ) + 1 ,
  2772.     ((( Round( Height * 0.75 ) - 6 ) - 32 ) div 2 ) + 1 , FTheIcon );
  2773.   end;
  2774. end;
  2775.  
  2776. { This procedure clears a scrollbox of all FileIconPanels }
  2777. procedure TFileIconPanelScrollbox.ClearTheFIPs;
  2778. var Counter_1 : Integer;
  2779.     TheComponent : TComponent;
  2780. begin
  2781.   { Note that must use while loop since component count continually }
  2782.   { decreases as removes are made!                                  }
  2783.   while ComponentCount > 0 do
  2784.   begin
  2785.     { Save the component as a generic TComponent }
  2786.     TheComponent := Components[ 0 ];
  2787.     { Call removecomponent to pull it out of the owner list for sb }
  2788.     { This avoids GPF when freeing the sb.                         }
  2789.     RemoveComponent( Components[ 0 ]);
  2790.     if ControlCount > 0 then
  2791.      RemoveControl( Controls[ 0 ] );
  2792.     { Typecast the pointer and free it to release memory and res. }
  2793.     TheParentForm.InsertComponent( TheComponent );
  2794.   end;
  2795. end;
  2796.  
  2797. { This procedure scans for drives and obtains their type and creates file }
  2798. { icon panels to represent them.                                          }
  2799. procedure TFileIconPanelScrollBox.AddDriveIcons( var XCounter ,
  2800.            YCounter : Integer );
  2801. type
  2802.   { This if from filectrl unit; reproduce here for completeness }
  2803.   TDriveType = (dtUnknown, dtNoDrive, dtFloppy, dtFixed, dtNetwork, dtCDROM,
  2804.                 dtRAM);
  2805. var
  2806.   DrivePC         : array[0..256] of char;
  2807.   DriveNum        : Integer;         { Used to get next drive via DOS fn   }
  2808.   IconType        : Integer;         { Used to hold icon type (defacto dt) }
  2809.   DriveChar       : Char;            { Used to hold drive letter           }
  2810.   DriveType       : TDriveType;      { Used for set-valued drive type      }
  2811.   Finished        : Boolean;         { Loop flag                           }
  2812.   TheFIP          : TFileIconPanel;  { Generic FileIconPanel variable      }
  2813.   ButtonColor   ,                    { Main panel color                    }
  2814.   ButtonHLColor ,                    { Bright panel color                  }
  2815.   ButtonSColor  ,                    { Dark panel color                    }
  2816.   Textcolor       : TColor;          { Label text color                    }
  2817.  
  2818. (*{ This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  2819. { Check whether drive is a CD-ROM.  Returns True if MSCDEX is installed }
  2820. {  and the drive is using a CD driver                                   }
  2821.  
  2822. function IsCDROM(DriveNum: Integer): Boolean; assembler;
  2823. asm
  2824.   MOV   AX,1500h { look for MSCDEX }
  2825.   XOR   BX,BX
  2826.   INT   2fh
  2827.   OR    BX,BX
  2828.   JZ    @Finish
  2829.   MOV   AX,150Bh { check for using CD driver }
  2830.   MOV   CX,DriveNum
  2831.   INT   2fh
  2832.   OR    AX,AX
  2833.   @Finish:
  2834. end;
  2835.  
  2836. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  2837. { Check whether drive is a RAM drive.                                   }
  2838. function IsRAMDrive(DriveNum: Integer): Boolean; assembler;
  2839. var
  2840.   TempResult: Boolean;
  2841. asm
  2842.   MOV   TempResult,False
  2843.   PUSH  DS
  2844.   MOV   BX,SS
  2845.   MOV   DS,BX
  2846.   SUB   SP,0200h
  2847.   MOV   BX,SP
  2848.   MOV   AX,DriveNum
  2849.   MOV   CX,1
  2850.   XOR   DX,DX
  2851.   INT   25h  { read boot sector }
  2852.   ADD   SP,2
  2853.   JC    @ItsNot
  2854.   MOV   BX,SP
  2855.   CMP   BYTE PTR SS:[BX+15h],0F8h  { reverify fixed disk }
  2856.   JNE   @ItsNot
  2857.   CMP   BYTE PTR SS:[BX+10h],1  { check for single FAT }
  2858.   JNE   @ItsNot
  2859.   MOV   TempResult,True
  2860.   @ItsNot:
  2861.   ADD   SP,0200h
  2862.   POP   DS
  2863.   MOV   AL, TempResult
  2864. end;
  2865.  
  2866. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  2867. { Finds the type of a drive letter.                                     }
  2868. function FindDriveType(DriveNum: Integer): TDriveType;
  2869. begin
  2870.   Result := TDriveType(GetDriveType(DriveNum));
  2871.   if (Result = dtFixed) or (Result = dtNetwork) then
  2872.   begin
  2873.     if IsCDROM(DriveNum) then Result := dtCDROM
  2874.     else if (Result = dtFixed) then
  2875.     begin
  2876.         { do not check for RAMDrive under Windows NT }
  2877.       if ((GetWinFlags and $4000) = 0) and IsRAMDrive(DriveNum) then
  2878.         Result := dtRAM;
  2879.     end;
  2880.   end;
  2881. end;*)
  2882.  
  2883. begin
  2884.   { Set the button colors to an aquamarine color scheme for drives }
  2885.   ButtonColor := clTeal;
  2886.   ButtonHLColor := clAqua;
  2887.   ButtonSColor := clNavy;
  2888.   TextColor := clblack;
  2889.   { Set initial variables before looping for all drives }
  2890.   finished := false;
  2891.   DriveNum := 0;
  2892.   while not finished do
  2893.   begin
  2894.     { Start with no drive found }
  2895.     IconType := 0;
  2896.     (*=============REMOVED DUE TO WINDOWS 95=========
  2897.     { Call the Borland method to get the drive info }
  2898.     DriveType := FindDriveType(DriveNum);
  2899.     ===============END WINDOWS 95 REMOVAL==========*)
  2900.     { Set its letter and make it uppercase }
  2901.     DriveChar := Chr(DriveNum + ord('a'));
  2902.     DriveChar := Upcase(DriveChar);
  2903.     StrPCopy( DrivePC , DriveChar + ':\' );
  2904.     {*&&&&&&&&&&&&&&&  WIN 95 CALL  &&&&&&&&&&&&&&&&&&&*}
  2905.     DriveType := TDriveType(GetDriveType( DrivePC ));
  2906.     { Assign an icon based on the drive type; if no drive exists type is nil }
  2907.     case DriveType of
  2908.       dtFloppy  : IconType := 1;
  2909.       dtFixed   : IconType := 2;
  2910.       dtNetwork : IconType := 3;
  2911.       dtCDROM   : IconType := 4;
  2912.       dtRAM     : IconType := 5;
  2913.     end;
  2914.     { Set to check next drive letter }
  2915.     DriveNum := DriveNum + 1;
  2916.     { But if no match then out of drives so set exit flag }
  2917.     if IconType = 0 then finished := true;
  2918.     { If drive was valid then set up the New FileIconPanel on the imported }
  2919.     { Scrollbox                                                            }
  2920.     if not finished then
  2921.     begin
  2922.       { Create the FileIconPanel and set its parent for memory mgmt and display}
  2923.       TheFIP := TFileIconPanel.Create( Self );
  2924.       TheFIP.Parent := Self;
  2925.       { Call its initialize method with imported position values and the   }
  2926.       { preset color scheme, a drive caption, and a minimum font. Note the }
  2927.       { setting of the ExtraData field to non-zero; this signals a drive   }
  2928.       { rather than a file being sent in.                                  }
  2929.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  2930.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  2931.         7 , ButtonColor, ButtonHLColor,
  2932.        ButtonSColor , TextColor , 'DRIVE ' + DriveChar + ':' , 'MS Serif' , [] ,
  2933.        IconType );
  2934.       { Increment the column counter; if it exceeds max move to New row      }
  2935.       { Note that these are 'var' parameters and will export final position. }
  2936.       XCounter := XCounter + 1;
  2937.       if XCounter > MaxIconsInARow then
  2938.       begin
  2939.         XCounter := 1;
  2940.         YCounter := YCounter + 1;
  2941.       end;
  2942.     end;
  2943.   end;
  2944. end;
  2945.  
  2946. { This procedure assigns colors to FIP's based on file attributes }
  2947. procedure TFileIconPanelScrollBox.GetColorsForFileIcon( TheFile : String;
  2948.            var BC , HC , SC , TC : TColor );
  2949. var AmADir      ,             { Booleans hold file attribs }
  2950.     AmAnArchive ,
  2951.     AmAVolumeId ,
  2952.     AmHidden    ,
  2953.     AmReadOnly  ,
  2954.     AmSystem      : Boolean;
  2955. begin
  2956.   { Make the call to internal fileworkbench to set attributes }
  2957.   TheFWB.GetFileAttributes( TheFile , AmADir , AmAnArchive , AmAVolumeId ,
  2958.    AmHidden , AmReadOnly , AmSystem );
  2959.   { Volume ID has no subtypes }
  2960.   if AmAVolumeID then
  2961.   begin
  2962.     BC := clOlive;
  2963.     HC := clYellow;
  2964.     SC := clBlack;
  2965.     TC := clWhite;
  2966.     exit;
  2967.   end;
  2968.   { Check all directory combinations }
  2969.   if AmADir then
  2970.   begin
  2971.     BC := clNavy;
  2972.     HC := clBlue;
  2973.     SC := clBlack;
  2974.     TC := clWhite;
  2975.     if AmHidden then
  2976.     begin
  2977.       if AmReadOnly then
  2978.       begin
  2979.         if AmSystem then
  2980.         begin { One HECK of a file! }
  2981.           BC := clBlack;
  2982.           HC := clSilver;
  2983.           SC := clGray;
  2984.           TC := clWhite;
  2985.         end
  2986.         else
  2987.         begin { Dir,RO,Hid }
  2988.           BC := clMaroon;
  2989.           HC := clFuchsia;
  2990.           SC := clGreen;
  2991.           TC := clWhite;
  2992.         end;
  2993.       end
  2994.       else
  2995.       begin { Dir,Hid }
  2996.         BC := clPurple;
  2997.         HC := clFuchsia;
  2998.         SC := clBlack;
  2999.         TC := clWhite;
  3000.       end;
  3001.     end
  3002.     else
  3003.     begin
  3004.       if AmReadOnly then
  3005.       begin
  3006.         if AmSystem then
  3007.         begin { Dir,RO,Sys }
  3008.           BC := clMaroon;
  3009.           HC := clLime;
  3010.           SC := clGreen;
  3011.           TC := clWhite;
  3012.         end
  3013.         else
  3014.         begin { Dir,RO }
  3015.           BC := clGreen;
  3016.           HC := clLime;
  3017.           SC := clBlack;
  3018.           TC := clWhite;
  3019.         end;
  3020.       end
  3021.       else
  3022.       begin
  3023.         if AmSystem then
  3024.         begin { Dir,Sys }
  3025.           BC := clMaroon;
  3026.           HC := clRed;
  3027.           SC := clBlack;
  3028.           TC := clWhite;
  3029.         end;
  3030.       end;
  3031.     end;
  3032.   end
  3033.   else { Archive Only; check all combinations }
  3034.   begin
  3035.     BC := clSilver;
  3036.     HC := clWhite;
  3037.     SC := clGray;
  3038.     TC := clBlack;
  3039.     if AmHidden then
  3040.     begin
  3041.       if AmReadOnly then
  3042.       begin
  3043.         if AmSystem then
  3044.         begin { Hid,RO,Sys }
  3045.           BC := clRed;
  3046.           HC := clLime;
  3047.           SC := clPurple;
  3048.           TC := clBlack;
  3049.         end
  3050.         else
  3051.         begin { RO,Hid }
  3052.           BC := clLime;
  3053.           HC := clFuchsia;
  3054.           SC := clMaroon;
  3055.           TC := clBlack;
  3056.         end;
  3057.       end
  3058.       else
  3059.       begin { Hid }
  3060.         BC := clFuchsia;
  3061.         HC := clWhite;
  3062.         SC := clPurple;
  3063.         TC := clBlack;
  3064.       end;
  3065.     end
  3066.     else
  3067.     begin
  3068.       if AmReadOnly then
  3069.       begin
  3070.         if AmSystem then
  3071.         begin { RO,Sys }
  3072.           BC := clRed;
  3073.           HC := clLime;
  3074.           SC := clMaroon;
  3075.           TC := clBlack;
  3076.         end
  3077.         else
  3078.         begin { RO }
  3079.           BC := clLime;
  3080.           HC := clWhite;
  3081.           SC := clGreen;
  3082.           TC := clBlack;
  3083.         end;
  3084.       end
  3085.       else
  3086.       begin
  3087.         if AmSystem then
  3088.         begin { System }
  3089.           BC := clRed;
  3090.           HC := clWhite;
  3091.           SC := clMaroon;
  3092.           TC := clBlack;
  3093.         end;
  3094.       end;
  3095.     end;
  3096.   end;
  3097. end;
  3098.  
  3099. { This procedure gets all icons for an given directory, including drives and }
  3100. { standard subdirectories. It does not get special combinations or h/ro/sys  }
  3101. procedure TFileIconPanelScrollbox.GetIconsForEntireDirectory(
  3102.             TargetPath  : String );
  3103. var Finished        : Boolean;         { Loop flag              }
  3104.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  3105.     TheResult       : Integer;         { return variable        }
  3106.     TempPath        : String;          { path for FF/FN         }
  3107.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  3108.     RowCounter    ,                    { position in row of FIP }
  3109.     ColumnCounter   : Integer;         { position in col of FIP }
  3110.     ButtonColor   ,                    { main panel color       }
  3111.     ButtonHLColor ,                    { bright panel color     }
  3112.     ButtonSColor  ,                    { dark panel color       }
  3113.     Textcolor       : TColor;          { label text color       }
  3114.     IsADir ,                           { Variable for file attr }
  3115.     IsAnArchive ,
  3116.     IsAVolumeID,
  3117.     IsAReadOnlyFile,
  3118.     IsAHiddenFile ,
  3119.     IsASystemFile     : Boolean;
  3120.     MaxTextLength     : Integer;       { Used to safely set size}
  3121. begin
  3122.   { hide during refresh }
  3123.   Visible := false;
  3124.   { Get the icon sizes }
  3125.   TheFIP := TFileIconPanel.Create( Self );
  3126.   TheFIP.Parent := Self;
  3127.   TheFIP.FTheLabel.Canvas.Font.Name := 'MS Serif';
  3128.   TheFIP.FTheLabel.Canvas.Font.Size := 7;
  3129.   MaxTextLength := TheFIP.FTheLabel.Canvas.TextWidth( 'COMMAND.COM' );
  3130.   TheFIP.Free;
  3131.   TheIconSize := MaxTextLength + 13;
  3132.   ThumbNailWidth := TheIconSize - 10;
  3133.   ThumbNailHeight := Round( TheIconSize * 0.75 ) - 15;
  3134.   TheIconSpacing := TheIconSize + 5;
  3135.   { Set up maximum icons per row based on screen size }
  3136.   MaxIconsInARow := ( Screen.Width div TheIconSpacing );
  3137.   { Set up the position counters }
  3138.   RowCounter := 1;
  3139.   ColumnCounter := 1;
  3140.   { Get the drives for the current machine }
  3141.   AddDriveIcons( ColumnCounter , RowCounter  );
  3142.   { Set up the initial variables }
  3143.   Finished := false;
  3144.   TempPath := TargetPath + '*.*';
  3145.   { Make the call to FindFirst set to get any file; will return '.' }
  3146.   { so discard it.                                                  }
  3147.   TheResult := FindFirst( TempPath , faAnyFile , TheSR );
  3148.   { loop through all files in the directory and look for directories }
  3149.   while not Finished do
  3150.   begin
  3151.     { Make call to FindNext, using only SearchRecord from FindFirst }
  3152.     TheResult := FindNext( TheSR );
  3153.     { A -1 result means no more files so exit }
  3154.     if TheResult <> 0 then finished := true else
  3155.     begin
  3156.       { Otherwise check for a directory attribute }
  3157.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  3158.        faDirectory ) then
  3159.       begin
  3160.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3161.          ButtonHLColor , ButtonSColor , TextColor );
  3162.         { If found create a New FileIconPanel on the imported scrollbox }
  3163.         { Note sending 0 ExtraData parameter to indicate file not drive }
  3164.         TheFIP := TFileIconPanel.Create( Self );
  3165.         TheFIP.Parent := Self;
  3166.         TheFIP.Initialize((( ColumnCounter - 1 ) * TheIconSpacing ),
  3167.          (( RowCounter - 1  ) * TheIconSpacing ) , TheIconSize, TheIconSize ,
  3168.           3 , 7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  3169.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  3170.         { Increment column counter and move to New row if past limit }
  3171.         ColumnCounter := ColumnCounter + 1;
  3172.         if ColumnCounter > MaxIconsInARow then
  3173.         begin
  3174.           ColumnCounter := 1;
  3175.           RowCounter := RowCounter + 1;
  3176.         end;
  3177.       end;
  3178.     end;
  3179.   end;
  3180.   { Set up New initialization variables }
  3181.   Finished := false;
  3182.   TempPath := TargetPath + '*.*';
  3183.   { Make needed call to FindFirst and discard '.' }
  3184.   TheResult := FindFirst( TempPath , faAnyFile , TheSR );
  3185.   while not Finished do
  3186.   begin
  3187.     { Loop through file again, this time getting only archive files }
  3188.     TheResult := FindNext( TheSR );
  3189.     { Result of -1 indicates no more files }
  3190.     if TheResult <> 0 then Finished := true else
  3191.     begin
  3192.       { If faArchive file then add New FileIconPanel }
  3193.       TheFWB.GetFileAttributes(( Targetpath + TheSR.Name ) , IsADir ,
  3194.        IsAnArchive , IsAVolumeId , IsAHiddenFile , IsAReadOnlyFile ,
  3195.         IsASystemFile );
  3196.       if (( IsAnArchive ) and ( not IsADir )) then
  3197.       begin
  3198.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3199.          ButtonHLColor , ButtonSColor , TextColor );
  3200.         { Initialize New FileIconPanel and call initialize, sending 0 ED }
  3201.         TheFIP := TFileIconPanel.Create( Self );
  3202.         TheFIP.Parent := Self;
  3203.         TheFIP.Initialize((( ColumnCounter - 1 ) * TheIconSpacing ),
  3204.          (( RowCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize ,
  3205.           3 , 7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  3206.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  3207.         { Increment column counter and if needed row counter }
  3208.         ColumnCounter := ColumnCounter + 1;
  3209.         if ColumnCounter > MaxIconsInARow then
  3210.         begin
  3211.           ColumnCounter := 1;
  3212.           RowCounter := RowCounter + 1;
  3213.         end;
  3214.       end;
  3215.     end;
  3216.   end;
  3217.   { Reset to visible }
  3218.   Visible := true;
  3219. end;
  3220.  
  3221. { Update method for FIPscrollbox }
  3222. procedure TFileIconPanelScrollBox.Update;
  3223. begin
  3224.   IconsNeedRefreshing := true;
  3225.   { Force a repaint }
  3226.   InvalidateRect( TheStoredHandle , nil , true );
  3227. end;
  3228.  
  3229. { Create method for FIPScrollbox }
  3230. constructor TFileIconPanelScrollBox.Create( AOwner : TComponent );
  3231. begin
  3232.   inherited Create( AOwner );
  3233.   TheFWB := TFileWorkBench.Create( Self );
  3234. end;
  3235.  
  3236. { This function returns the next selected file's name }
  3237. function TFileIconPanelScrollBox.GetNextSelection( SourceDirectory : String;
  3238.                            var CurrentItem : Integer ) : String;
  3239. var TheResult    : String;      { Holds result of function }
  3240.     TheComponent : TComponent;  { Used for typecast        }
  3241.     finished     : boolean;     { Loop control variable    }
  3242.     TheComponentCount : Integer;
  3243. begin
  3244.   TheComponentCount := ComponentCount;
  3245.   { If past end of components exit with no result }
  3246.   if CurrentItem > TheComponentCount then TheResult := '' else
  3247.   begin
  3248.     { Set loop counter and run till find match or run out }
  3249.     finished := false;
  3250.     while not finished do
  3251.     begin
  3252.       { Pull component out of the list and check it }
  3253.       TheComponent := Components[ CurrentItem - 1 ];
  3254.       { Increment counter for later }
  3255.       CurrentItem := CurrentItem + 1;
  3256.       { Do the typecast with AS }
  3257.       if TheComponent is TFileIconPanel then
  3258.       with TheComponent as TFileIconPanel do
  3259.       begin
  3260.         { If its selected make sure OK }
  3261.         if Selected then
  3262.         begin
  3263.           { Don't accept backup for this level of operation }
  3264.           if FTheLabel.Caption <> '..' then
  3265.           begin
  3266.             { Otherwise return the name and abort the loop }
  3267.             TheResult := FTheName;
  3268.             finished := true;
  3269.           end;
  3270.         end
  3271.         else
  3272.         begin
  3273.           { Check to see if out of components }
  3274.           if CurrentItem > TheComponentCount then
  3275.           begin
  3276.             { If so signal error and abort }
  3277.             TheResult := '';
  3278.             finished := true;
  3279.           end;
  3280.         end;
  3281.       end;
  3282.     end;
  3283.   end;
  3284.   GetNextSelection := TheResult;
  3285. end;
  3286.  
  3287. { This procedure places a selection of files in the display based on wildcards }
  3288. procedure TFileIconPanelScrollBox.DisplayRecursiveSearchResults(
  3289.            TheStartingDirectory : String );
  3290. var XCounter ,
  3291.     YCounter   : Integer;
  3292.  
  3293. { This procedure does a recursive file search by first getting all matches (in-}
  3294. { cluding directories) and adding them to the list. Then it checks for ALL the }
  3295. { subdirectories and does the same trick on them til there are no more matches }
  3296. { and no more subdirectories, at which point it exits and recurses back up.    }
  3297. procedure RecursiveFileSearch( TheWorkingDirectory : String; var XCounter ,
  3298.                                YCounter : Integer );
  3299.  
  3300. { VITAL!!! These variables MUST be local for recursrion to work! }
  3301. var
  3302.     Finished        : Boolean;         { Loop flag              }
  3303.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  3304.     TheResult       : Integer;         { return variable        }
  3305.     TargetPath ,
  3306.     FileMask   ,
  3307.     TheStoredWorkingDirectory ,
  3308.     ModifiedDirectory  : String;       { path for FF/FN         }
  3309.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  3310.     ButtonColor   ,                    { main panel color       }
  3311.     ButtonHLColor ,                    { bright panel color     }
  3312.     ButtonSColor  ,                    { dark panel color       }
  3313.     Textcolor       : TColor;          { label text color       }
  3314.  
  3315. begin
  3316.   { Jump out if abort pressed }
  3317.   if GlobalAbortFlag then exit;
  3318.   { Set up the initial variables }
  3319.   Finished := false;
  3320.   TheStoredWorkingDirectory := TheWorkingDirectory;
  3321.   Targetpath := ExtractFilePath( TheWorkingDirectory );
  3322.   FileMask := ExtractFileName( TheWorkingDirectory );
  3323.   { Make the call to FindFirst set to get any file }
  3324.   TheResult := FindFirst( TheWorkingDirectory , faAnyFile , TheSR );
  3325.   if TheResult < 0 then finished := true;
  3326.   if (( TheSr.Name <> '.' ) and ( TheSr.Name <> '..' ) and ( TheResult >= 0 ))
  3327.   then begin
  3328.     if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  3329.      faDirectory ) then
  3330.     begin { A directory }
  3331.       GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3332.        ButtonHLColor , ButtonSColor , TextColor );
  3333.       { If found create a New FileIconPanel on the imported scrollbox }
  3334.       { Note sending 0 ExtraData parameter to indicate file not drive }
  3335.       TheFIP := TFileIconPanel.Create( Self );
  3336.       TheFIP.Parent := Self;
  3337.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  3338.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  3339.         7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor , TargetPath
  3340.          + TheSr.Name , 'MS Serif' , [] , 0 );
  3341.       { Increment column counter and move to New row if past limit }
  3342.       XCounter := XCounter + 1;
  3343.       if XCounter > MaxIconsInARow then
  3344.       begin
  3345.         XCounter := 1;
  3346.         YCounter := YCounter + 1;
  3347.       end;
  3348.     end
  3349.     else
  3350.     begin { A File }
  3351.       { Set up the default color scheme for files }
  3352.       GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3353.        ButtonHLColor , ButtonSColor , TextColor );
  3354.       { If found create a New FileIconPanel on the imported scrollbox }
  3355.       { Note sending 0 ExtraData parameter to indicate file not drive }
  3356.       TheFIP := TFileIconPanel.Create( Self );
  3357.       TheFIP.Parent := Self;
  3358.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  3359.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize, TheIconSize , 3 ,
  3360.         7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor , TargetPath
  3361.          + TheSr.Name , 'MS Serif' , [] , 0 );
  3362.       { Increment column counter and move to New row if past limit }
  3363.       XCounter := XCounter + 1;
  3364.       if XCounter > MaxIconsInARow then
  3365.       begin
  3366.         XCounter := 1;
  3367.         YCounter := YCounter + 1;
  3368.       end;
  3369.     end;
  3370.   end;
  3371.   { loop through all files in the directory and look for matches }
  3372.   while not Finished do
  3373.   begin
  3374.     { Allow keyboard processing and jump out if c-break hit }
  3375.     Application.ProcessMessages;
  3376.     if GlobalAbortFlag then exit;
  3377.     { Make call to FindNext, using only SearchRecord from FindFirst }
  3378.     TheResult := FindNext( TheSR );
  3379.     { A -1 result means no more files so exit }
  3380.     if TheResult <> 0 then finished := true else
  3381.     begin
  3382.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  3383.        faDirectory ) then
  3384.       begin { A directory }
  3385.         { Set up the blue color scheme for directories }
  3386.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3387.          ButtonHLColor , ButtonSColor , TextColor );
  3388.         { If found create a New FileIconPanel on the imported scrollbox }
  3389.         { Note sending 0 ExtraData parameter to indicate file not drive }
  3390.         TheFIP := TFileIconPanel.Create( Self );
  3391.         TheFIP.Parent := Self;
  3392.         TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  3393.          (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  3394.            7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  3395.             TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  3396.         { Increment column counter and move to New row if past limit }
  3397.         XCounter := XCounter + 1;
  3398.         if XCounter > MaxIconsInARow then
  3399.         begin
  3400.           XCounter := 1;
  3401.           YCounter := YCounter + 1;
  3402.         end;
  3403.       end
  3404.       else
  3405.       begin { A File }
  3406.         { Set up the default color scheme for files }
  3407.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3408.          ButtonHLColor , ButtonSColor , TextColor );
  3409.         { If found create a New FileIconPanel on the imported scrollbox }
  3410.         { Note sending 0 ExtraData parameter to indicate file not drive }
  3411.         TheFIP := TFileIconPanel.Create( Self );
  3412.         TheFIP.Parent := Self;
  3413.         TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  3414.          (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  3415.           7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  3416.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  3417.         { Increment column counter and move to New row if past limit }
  3418.         XCounter := XCounter + 1;
  3419.         if XCounter > MaxIconsInARow then
  3420.         begin
  3421.           XCounter := 1;
  3422.           YCounter := YCounter + 1;
  3423.         end;
  3424.       end;
  3425.     end;
  3426.   end;
  3427.   { Set up the variables to do recursive calls on all directories}
  3428.   Finished := false;
  3429.   ModifiedDirectory := ExtractFilePath( TheWorkingdirectory ) + '*.*';
  3430.   { Make the call to FindFirst set to get any file, ignore result }
  3431.   TheResult := FindFirst( ModifiedDirectory , faDirectory , TheSR );
  3432.   while not Finished do
  3433.   begin
  3434.     { Allow keyboard input and jump out if c-break hit }
  3435.     Application.ProcessMessages;
  3436.     if GlobalAbortFlag then exit;
  3437.     { Make call to FindNext, using only SearchRecord from FindFirst }
  3438.     TheResult := FindNext( TheSR );
  3439.     { A -1 result means no more files so exit }
  3440.     if TheResult <> 0 then finished := true
  3441.     else
  3442.     begin
  3443.       if TheSR.Name <> '..' then { Ignore backup in this case }
  3444.       begin
  3445.         { Do second check due to bug in FindNext }
  3446.         if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  3447.         = faDirectory ) then
  3448.         begin
  3449.           { Set up modified directory to recurse into }
  3450.           ModifiedDirectory := ExtractFilePath( TheStoredWorkingDirectory ) +
  3451.            TheSR.Name + '\' + FileMask;
  3452.           { Perform the recursion }
  3453.           RecursiveFileSearch( ModifiedDirectory , XCounter , YCounter );
  3454.         end;
  3455.       end;
  3456.     end;
  3457.   end;
  3458. end;
  3459.  
  3460. begin
  3461.   { Keep the scrollbox from updating during refresh }
  3462.   Visible := false;
  3463.   { Make the clear call }
  3464.   ClearTheFIPs;
  3465.   XCounter := 1;
  3466.   YCounter := 1;
  3467.   { Get the drives for the current machine }
  3468.   AddDriveIcons( XCounter , YCounter );
  3469.   RecursiveFileSearch( TheStartingDirectory , XCounter , YCounter );
  3470.   { Make the scrollbox visible again }
  3471.   Visible := true;
  3472. end;
  3473.  
  3474. end.
  3475.